【发布时间】:2017-05-31 10:16:27
【问题描述】:
我有时想检查来自我们域中服务器的一些信息。在这个例子中,我试图远程获取 windows 版本(只有一台服务器,目前没有循环):
$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 和 ComputerName 是别名。我试过长名称和输出(错误)是一样的。