Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ghotz/8eb13e498a9f57a2a235b11bbc4227fe to your computer and use it in GitHub Desktop.

Select an option

Save ghotz/8eb13e498a9f57a2a235b11bbc4227fe to your computer and use it in GitHub Desktop.
Generate dbatools cmdlet calls to enable/disable jobs
$Commands = @(); $Source = "oldsqlname"; $Destination = "newsqlname";
Get-DbaAgentJob -SqlInstance $Source | % { $Commands += "Set-DbaAgentJob -SqlInstance $Destination -Job `"$($_.Name)`" $(if ($_.Enabled) { `"-Enabled;`" } else { `"-Disabled;`" })" };
Write-Output @Commands
$Commands = @(); $Source = "oldsqlname"; $Destination = "newsqlname";
Get-DbaAgentJob -SqlInstance $Source | % { $Commands += "Set-DbaAgentJob -SqlInstance $Destination -Job `"$($_.Name)`" -Disabled;" };
Write-Output @Commands
$Commands = @(); $Source = "oldsqlname"; $Destination = "newsqlname";
Get-DbaAgentJob -SqlInstance $Source | % { $Commands += "Set-DbaAgentJob -SqlInstance $Destination -Job `"$($_.Name)`" $(if ($_.Enabled) { `"-Enabled;`" } else { `"-Disabled;`" })" };
Write-Output @Commands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment