Created
May 24, 2022 09:59
-
-
Save jpomfret/e4942920842c131a9fd665e33d547ef6 to your computer and use it in GitHub Desktop.
Copying logins & jobs from one server to another, but would also like to script them out for source control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## I'd like to copy logins/jobs but also script them out for source control | |
# get logins from source | |
$logins = Get-DbaLogin -SqlInstance $dbatools1 | |
# first export, then copy | |
$logins | Export-DbaLogin -FilePath ('Export\Logins_{0}.sql' -f (get-date -f 'yyyyMMdd_hhmmss')) | |
$logins | Copy-DbaLogin -Destination $dbatools2 | |
# get jobs from source | |
$jobs = Get-DbaAgentJob -SqlInstance $dbatools1 | |
# first export, then copy | |
$jobs | Export-DbaScript -FilePath ('Export\Jobs{0}.sql' -f (get-date -f 'yyyyMMdd_hhmmss')) | |
$jobs | Copy-DbaAgentJob -Destination $dbatools2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment