hyper v pause

Jun 23, 2010 at 1:09 AM

Hi, 

we have a number of vm servers thast are running across a number of hosts.  a number of these servers are production and a number of these are used by user to do a lot of testing.  We would like to be able to run a powershell script that pauses a certain list of servers.  Below is a script that shuts down all servers on host but i would like to be able to select the ones i want.  Within the properties of a virtual machine under general there is a tag field.  if possible i would like to be able to put servers in a saved/paused stated depending on the tag they have or if its easier just the server name.

-------------------Script to pause all VMs ------------------------------------------------

##
##    Create VM State table
##

$State     =     @{‘Enabled’ = 2 ; ‘Disabled’= 3;  ‘Paused’= 32768 ; ‘Suspended’ = 32769 ; ‘Starting’ = 32770 ; ‘Snapshotting’ = 32771 ;  `
         ‘Migrating’ = 32772 ; ‘Saving’ = 32773 ; ‘Stopping’ = 32774 ; ‘Deleted’ = 32775 ; ‘Pausing’ = 32776 }

2..15 | % {

$server = "HVHOST{0:D2}" -f $_
$VM_Service = get-wmiobject -computername $server -namespace root\virtualization Msvm_VirtualSystemManagementService
$ListofVMs =get-wmiobject -computername $server -namespace root\virtualization Msvm_ComputerSystem -filter  "ElementName <> Name " 

foreach ($VM in $ListOfVMs)
{
    write-host -foreground yellow "Saving state VM $($VM.ElementName) now"
    $VM.RequestStateChange($State['Suspended'])
}

 

}

---------------------------------- End of Script ---------------------------------------------------

 

Any help much appreciated.

Thanks