Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
循环获取虚拟机Powershell_Powershell - Fatal编程技术网

循环获取虚拟机Powershell

循环获取虚拟机Powershell,powershell,Powershell,我在寻找一个脚本,它得到虚拟机*然后进入“睡眠”5秒,然后再次得到虚拟机 到目前为止,我想到了这个: cls get-vm * Start-Sleep 5 但它只写了一次 什么是使其进入循环的正确代码?如果您想要无休止的循环: while ($true) { cls Write-Host "Getting VMs at $(get-date)" get-vm * Start-Sleep 5 } 使用Ctrl+C结束循环。Hello。Powershell正在接受脚本,但未提

我在寻找一个脚本,它得到虚拟机*然后进入“睡眠”5秒,然后再次得到虚拟机

到目前为止,我想到了这个:

cls
get-vm *
Start-Sleep 5
但它只写了一次


什么是使其进入循环的正确代码?

如果您想要无休止的循环:

while ($true)
{
  cls 
  Write-Host "Getting VMs at $(get-date)"
  get-vm * 
  Start-Sleep 5
}

使用Ctrl+C结束循环。

Hello。Powershell正在接受脚本,但未提供任何输出?添加了一个写入主机以验证它是否正在运行。如果它只显示这个,那么get-vm*不会返回任何结果。我不确定你的意思是什么?你能试着举个例子吗?如果我在一个普通的powershell提示符中写“Get VM*”,那么它可以正常工作。我更新了发布的脚本。如果你这样做会得到什么?