ca9163d9
ca9163d9

Reputation: 29247

Script block of Start-Job hang in Powershell?

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

Answers (2)

jon Z
jon Z

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

Related Questions