开发者

Get-WmiObject with credential fails when within Start-Job scriptblock

开发者 https://www.devze.com 2023-02-07 14:51 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消