1

I am successfully retrieving some information from Windows 2000 machines using the Get-WmiObjet cmdlet. These machines are not part of our domain so I am using the -Credential parameter to pass local administrator credentials.

I am now trying to run several WMI queries in parallel using Start-Job but I can't get even one query to work.

When I run the following:

Start-Job -initializationscript {$cred = get-credential -credential administrator}  -scriptblock {gwmi win32_computersystem -ComputerName 10.1.2.3 -Credential $cred}

a job is created, I am prompted for the credentials, but the job never completes, its state is always "Running".

Of course:

C:\>$cred = Get-Credential -credential administrator
C:\>gwmi win32_computersystem -ComputerName 10.1.2.3 -Credential $cred

works just fine.

How do I get Get-WmiObject to run successfully within Start-Job with alternate credentials?

Thanks for your help.

Lucas
  • 23
  • 2
  • 5

1 Answers1

3

Try this:

$cred = Get-Credential -Credential Administrator
Start-Job -scriptblock {Param ($cred) gwmi win32_computersystem -ComputerName 10.1.2.3 -Credential $cred} -ArgumentList $cred

Looks like the background job is blocked for input and has been running forever for that reason.

ravikanth
  • 24,922
  • 4
  • 60
  • 60
  • Also the reason I didnt' try to use -ArgumentList is because the help is misleading. I found out that a bug has been submitted via Microsoft Connect: – Lucas Feb 01 '11 at 17:57
  • Link to the bug: http://connect.microsoft.com/PowerShell/feedback/details/563695/argumentlist-parameter-to-start-job-incomplete – Lucas Feb 01 '11 at 17:58
  • For the sake of completeness, this question had been answered before on this site: http://stackoverflow.com/questions/1691612/make-a-powershell-function-task-run-in-the-background – Lucas Feb 01 '11 at 18:55