You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Perhaps I am just misunderstanding the way this should work. This is basically what my code looks like:
$datatable = Invoke-Sqlcmd2 -ServerInstance MyServer -Database MyDatabase -Query @" SELECT ID, SourceServer, DbName, DestinationServer FROM myTable WHERE ID in (1,2,3,4,5) "@ [void]$(($datatable.Rows)|Start-RSJob -Name {"$($_.ID)-$($_.DbName)"} -Throttle 10 -ScriptBlock { #Really long complicated script block which restores, manipulates and backups up databases }) [void] $(Get-RSJob | Wait-RSJob) [void] $(Get-RSJob | Stop-RSJob) [void] $(Get-RSJob | Remove-RSJob) $MailMessage = new-object System.Net.Mail.MailMessage $MailMessage... #Fill in appropriate properties for the mail message object $smpt = new-object Net.Mail.SmtpClient("smtp.server.com") $smtp.Send($MailMessage)
When I run my code from PS ISE, it runs all of the jobs for each of the 5 databases I feed it before sending the email which includes information on the success/failure of each job. When I run this script from a SQL Agent job as either a powershell or a call from the Operating System (CmdExec), it only waits for the first job to complete/error before sending the email which shows one job finished and 4 running. The server only shows one powershell instance running, but none of the other jobs ever finish. The same thing happens when run from a Scheduled Task. Any clue why Wait-RSJob does not get respected by TaskScheduler or SQLAgent?
The text was updated successfully, but these errors were encountered:
Good call MVKozlov. Someone went and encrypted a database then turned encryption off. I was checking for encryption status but not the existence of a database key. Apparently, you can't restore an unencrypted database without the certificate if the database key exists.
Perhaps I am just misunderstanding the way this should work. This is basically what my code looks like:
$datatable = Invoke-Sqlcmd2 -ServerInstance MyServer -Database MyDatabase -Query @" SELECT ID, SourceServer, DbName, DestinationServer FROM myTable WHERE ID in (1,2,3,4,5) "@ [void]$(($datatable.Rows)|Start-RSJob -Name {"$($_.ID)-$($_.DbName)"} -Throttle 10 -ScriptBlock { #Really long complicated script block which restores, manipulates and backups up databases }) [void] $(Get-RSJob | Wait-RSJob) [void] $(Get-RSJob | Stop-RSJob) [void] $(Get-RSJob | Remove-RSJob) $MailMessage = new-object System.Net.Mail.MailMessage $MailMessage... #Fill in appropriate properties for the mail message object $smpt = new-object Net.Mail.SmtpClient("smtp.server.com") $smtp.Send($MailMessage)
When I run my code from PS ISE, it runs all of the jobs for each of the 5 databases I feed it before sending the email which includes information on the success/failure of each job. When I run this script from a SQL Agent job as either a powershell or a call from the Operating System (CmdExec), it only waits for the first job to complete/error before sending the email which shows one job finished and 4 running. The server only shows one powershell instance running, but none of the other jobs ever finish. The same thing happens when run from a Scheduled Task. Any clue why Wait-RSJob does not get respected by TaskScheduler or SQLAgent?
The text was updated successfully, but these errors were encountered: