0
我希望有时检查域中服务器的某些信息。在这个例子中,我尝试远程获取Windows版本(只有一个服务器,目前无环路):Powershell:Get-WmiObject无法在循环中作为运行环境运行
$cr=Get-Credential "domain\adm_user"
$computer="serverA"
Invoke-Command { Get-WmiObject -Class Win32_OperatingSystem -Namespace root/cimv2 -Computer $computer -Credential $cr | Format-List -Property Name, OSArchitecture, SerialNumber} -AsJob -ComputerName .
Get-Job | Wait-Job
Get-Job | Receive-Job
输出:
Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
看来,该脚本块{}不能看到变量$computer
。 当我将变量-computer $computer
替换为服务器的名称时,它正在工作。
正确的参数是'-ComputerName' - 你正在使用-Computer? – Jelphy
Computer和ComputerName是别名。我尝试了很长的名字和输出(错误)是一样的。 – Jerry1