在 Start-Job 脚本块内时,带有凭据的 Get-WmiObject 失败
我使用 Get-WmiObjet cmdlet 成功从 Windows 2000 计算机检索一些信息。这些计算机不是我们域的一部分,因此我使用 -Credential 参数来传递本地管理员凭据。
我现在尝试使用 Start-Job 并行运行多个 WMI 查询,但我什至无法让一个查询工作。
当我运行以下命令时:
Start-Job -initializationscript {$cred = get-credential -credential administrator} -scriptblock {gwmi win32_computersystem -ComputerName 10.1.2.3 -Credential $cred}
创建了一个作业,系统会提示我输入凭据,但该作业永远不会完成,其状态始终为“正在运行”。
当然:
C:\>$cred = Get-Credential -credential administrator
C:\>gwmi win32_computersystem -ComputerName 10.1.2.3 -Credential $cred
效果很好。
如何使用备用凭据让 Get-WmiObject 在 Start-Job 中成功运行?
感谢您的帮助。
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:
Looks like the background job is blocked for input and has been running forever for that reason.