Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Wait-RSjob #181

Closed
chadwestes opened this issue May 8, 2018 · 2 comments
Closed

Issue with Wait-RSjob #181

chadwestes opened this issue May 8, 2018 · 2 comments

Comments

@chadwestes
Copy link

chadwestes commented May 8, 2018

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?

@MVKozlov
Copy link
Contributor

MVKozlov commented May 8, 2018

Did you try to just { write-host "number $_" } instead of you long scriptblock ?
may be there is some exception inside ?

which version of module you use, what commands inside your sriptblock you use ?

if you use invoke-sqlcmd inside you scriptblock, may be invoke-sqlcmd incompatible with poshrsjob (see #173)

@chadwestes
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants