Get-VM $Paused Switch may be useful

Jun 1, 2011 at 7:13 PM

While Executing: Get-VM

NOTE: I may have an older version where this is not supported yet, but if a specific filter for "Paused" is desired, it is not available like $Running, $Suspended and $Stopped for this command.

I needed this functionality because I wanted to quickly retrieve VMs that were in a $Suspended, $Stopped AND $Paused state. I could have filtered for "Paused" after the fact, but I saw how easy it was to use the switches for $Suspended and $Stopped so I wondered if it would be worth adding a $Paused switch.

As a quick update for my purposes, I just added the following to the VM.ps1 file:

To the State Parameter (around Line 50):


To the If Statement starting around Line 64:

            if ($Running -or $Stopped -or $Suspended -or $Paused) {
                $state = ""
                if ($Running)   {$State += " or enabledState = " + [int][VMState]::Running   }
                if ($Stopped)   {$State += " or enabledState = " + [int][VMState]::Stopped   }
                if ($Suspended) {$State += " or enabledState = " + [int][VMState]::Suspended }
                if ($Paused)    {$State += " or enabledState = " + [int][VMState]::Paused }
                $state = $state.substring(4) 
                $WQL += " AND ($state)"

This way, the "Paused" state can be baked right into $WQL.