VMware Communities
TryllZ
Expert
Expert
Jump to solution

Resuming Suspended VMs in Workstation with Powershell..

Hi,

I have this following script which "starts" and NOT "resume" the VMs in workstation, the issue being those VMs which are shutdown start as well.

What I intend to do is to resume only VMs that are suspended and NOT all VMs in workstation list.

The idea I have in mind is to check which VMs have vmem file in their folder (in this case D:\VIRTUALMACHINES), only those should be resumed, just not sure how to apply it.

cd "C:\Program Files (x86)\VMware\VMware Workstation"

$SuspendedVMs = gci -Include *.vmx -Recurse -Path D:\VIRTUALMACHINES

Foreach ($SuspendedVM in $SuspendedVMs)

{

.\vmrun start "$SuspendedVM"

}

0 Kudos
1 Solution

Accepted Solutions
TryllZ
Expert
Expert
Jump to solution

Solved it, now it ONLY resumes suspended VMs in Workstation.

if (Get-Process vmware -ErrorAction silentlycontinue)

  {

    cd "C:\Program Files (x86)\VMware\VMware Workstation"

    $RunningVMs = .\vmrun list | select-object -skip 1

    Foreach ($RunningVM in $RunningVMs)

  {

    "Suspending $RunningVM..."

    .\vmrun suspend "$RunningVM"

  }

  "Quitting VMWare Workstation.."

  Stop-Process -Name vmware

}

else

  {

    "Opening VMWare Workstation.."

    Start-Process -FilePath "C:\Program Files (x86)\VMware\VMware Workstation\vmware.exe" -WindowStyle Maximized

    cd "C:\Program Files (x86)\VMware\VMware Workstation"

    $Checkvmems = gci -Include *.vmem -Recurse -Path D:\VIRTUALMACHINES

    Foreach ($Checkvmem in $Checkvmems)

  {

    $FolderPath = [System.IO.Path]::GetDirectoryName("$Checkvmem")

    $SuspendedVMs = gci -Include *.vmx -Recurse -Path $FolderPath

    Foreach ($SuspendedVM in $SuspendedVMs)

  {

    "Resuming $SuspendedVM"

    .\vmrun start "$SuspendedVM"

  }

}

}

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.

View solution in original post

0 Kudos
2 Replies
TryllZ
Expert
Expert
Jump to solution

Solved it, now it ONLY resumes suspended VMs in Workstation.

if (Get-Process vmware -ErrorAction silentlycontinue)

  {

    cd "C:\Program Files (x86)\VMware\VMware Workstation"

    $RunningVMs = .\vmrun list | select-object -skip 1

    Foreach ($RunningVM in $RunningVMs)

  {

    "Suspending $RunningVM..."

    .\vmrun suspend "$RunningVM"

  }

  "Quitting VMWare Workstation.."

  Stop-Process -Name vmware

}

else

  {

    "Opening VMWare Workstation.."

    Start-Process -FilePath "C:\Program Files (x86)\VMware\VMware Workstation\vmware.exe" -WindowStyle Maximized

    cd "C:\Program Files (x86)\VMware\VMware Workstation"

    $Checkvmems = gci -Include *.vmem -Recurse -Path D:\VIRTUALMACHINES

    Foreach ($Checkvmem in $Checkvmems)

  {

    $FolderPath = [System.IO.Path]::GetDirectoryName("$Checkvmem")

    $SuspendedVMs = gci -Include *.vmx -Recurse -Path $FolderPath

    Foreach ($SuspendedVM in $SuspendedVMs)

  {

    "Resuming $SuspendedVM"

    .\vmrun start "$SuspendedVM"

  }

}

}

---------------------------------------------------------------------------------------------------------

Was it helpful? Let us know by completing this short survey here.

0 Kudos
brapow
Contributor
Contributor
Jump to solution

This is also wrong for Vmware Workstation 16 , you should look for vmss files. Here is the corrected script.

 

 cd "C:\Program Files (x86)\VMware\VMware Workstation"

$Checkvmems = gci -Include *.vmss -Recurse -Path E:\VmwareMachines

    Foreach ($Checkvmem in $Checkvmems)

  {

    $FolderPath = [System.IO.Path]::GetDirectoryName("$Checkvmem")

    $SuspendedVMs = gci -Include *.vmx -Recurse -Path $FolderPath

    Foreach ($SuspendedVM in $SuspendedVMs)

  {

    Write-Output "Resuming $SuspendedVM"

    .\vmrun start "$SuspendedVM"

  }

 } 

0 Kudos