在 Start-Job 脚本块中使用凭据获取 WmiObject 失败 [英] Get-WmiObject with credential fails when within Start-Job scriptblock
问题描述
我使用 Get-WmiObjet cmdlet 从 Windows 2000 机器成功检索了一些信息.这些机器不是我们域的一部分,所以我使用 -Credential 参数来传递本地管理员凭据.
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.
我现在尝试使用 Start-Job 并行运行多个 WMI 查询,但我什至无法使一个查询工作.
I am now trying to run several WMI queries in parallel using Start-Job but I can't get even one query to work.
当我运行以下命令时:
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".
当然:
C:\>$cred = Get-Credential -credential administrator
C:\>gwmi win32_computersystem -ComputerName 10.1.2.3 -Credential $cred
工作正常.
如何使用备用凭据让 Get-WmiObject 在 Start-Job 中成功运行?
How do I get Get-WmiObject to run successfully within Start-Job with alternate credentials?
感谢您的帮助.
推荐答案
试试这个:
$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.
这篇关于在 Start-Job 脚本块中使用凭据获取 WmiObject 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!