TryllZ
Hot Shot
Hot Shot

Resuming Suspended VMs in Workstation with Powershell..

Jump to solution

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
Hot Shot
Hot Shot

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
1 Reply
TryllZ
Hot Shot
Hot Shot

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