문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top