Skip to content

Instantly share code, notes, and snippets.

@jpomfret
Created May 24, 2022 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpomfret/e4942920842c131a9fd665e33d547ef6 to your computer and use it in GitHub Desktop.
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
## 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