powershell 关闭系统前挂起vmware workstation 的所有虚机

来源:互联网 发布:mysql exist的用法 编辑:程序博客网 时间:2024/04/30 12:07

所有虚机都在e:\vm目录下,有时候挂起虚机会不成功,会报错,当报错的时候重新挂起一次


$vm=Get-ChildItem -Path 'e:\vm' -Include *.vmx -recurse | Get-Item -Stream * | ft filename |Out-String -Stream
$j=2
while ($j -eq 2)
{
    $j=1
    $msg=""
    foreach ($i in $vm)
        {       
        $msg=vmrun -t ws suspend  "$i" | Out-String
        $i
        if ($msg.Contains("Error: Unknown error")) 
            {
            $j=2
            $msg  
            Start-Sleep -s 10
            }         
        }
}


0 0