【发布时间】:2019-04-19 22:02:54
【问题描述】:
我把头发拉出来了,因为我似乎无法让它工作,而且我不知道如何用谷歌搜索这个问题。我正在运行 Powershell 2.0。这是我的脚本:
$computer_names = "server1,server2"
Write-Output "Invoke-Command -ComputerName $computer_names -ScriptBlock {
Get-WmiObject -Class Win32_LogicalDisk |
sort deviceid |
Format-Table -AutoSize deviceid, freespace
}"
Invoke-Command -ComputerName $computer_names -ScriptBlock {
Get-WmiObject -Class Win32_LogicalDisk |
sort deviceid |
Format-Table -AutoSize deviceid, freespace
}
最后一条命令报错:
Invoke-Command : One or more computer names is not valid. If you are trying to
pass a Uri, use the -ConnectionUri parameter or pass Uri objects instead of
strings.
但是当我将 Write-Output 命令的输出复制到 shell 并运行它时,它工作得很好。如何将字符串变量转换为 Invoke-Command 将接受的内容?提前致谢!
【问题讨论】:
标签: powershell powershell-2.0 powershell-remoting