Reputation: 29247
I have the following script. The created background job never finishes. (It finishes in a few seconds if I just run the scripts in the -ScriptBlock { ... }
).
Edit:
My machine is XP/sp3. This may be the reason of hang as Jon found out.
Start-Job -ScriptBlock {
if ( (Get-PSSnapin -Name Sql* -ErrorAction SilentlyContinue) -eq $null )
{
Add-PSSnapin Sql*
}
Invoke-Sqlcmd -Query "select 1 a" -ServerInstance serverX -ErrorAction stop
}
Receive-Job *
returns nothing and Get-Job
always returns the following lines.
> Get-Job
Id Name State HasMoreData Location Command
-- ---- ----- ----------- -------- -------
29 Job29 Running True localhost ...
Upvotes: 3
Views: 3309
Reputation: 52480
Actually, you're hitting this bug:
...which is apparently because of: http://support.microsoft.com/kb/2009703
Upvotes: 4
Reputation: 16646
Your code seems to be working in my test environment (Windows 7). You might be experiencing this (Background jobs keep running infinitely in Win XP SP3) on Windows XP/2003.
Upvotes: 4