我是powershell的新手,我有一个powershell脚本应该同时在我的主机中的每个虚拟机上运行。我的一位朋友告诉我,菲利普斯开发了一种工具,但是我搜索了它却无法找到。如果有任何工具可以帮助我解决问题。
提前致谢
答案 0 :(得分:1)
您可以在脚本块中创建脚本并在枚举VM时运行它。
# On the host, Get-VM get's you the available VMs.
$runniungVMs = $Get-VM -State 'Running'
foreach ($vm in $runningVMs) {
Enter-PSSession $vm
# Write Some code to execute after this line
}
Invoke-Command –ComputerName <computerName> -Credential $Cred –ScriptBlock {
# Write some code to execute
}
更新其他问题
Get-VM 命令获取运行该命令的主机上可用的虚拟机列表。
如果您的VM主机不是您运行的计算机,则可以指定VM主机的计算机名称。以下是如何获取Server1上正在运行的VM的列表:
Get-VM -ComputerName Server1 | Where-Object {$_.State -eq 'Running'}
Posh也提供了很大的帮助。如果您需要了解有关任何命令的更多信息,请使用:
get-help Get-VM
或
get-help Get-VM -examples
get-help Get-VM -detailed
get-help Get-VM -full