header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
pause vm machines
Last Post 28 Jun 2010 08:30 PM by phillbl. 6 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Resolved
phillblUser is Offline
New Member
New Member
Posts:9
Avatar

--
22 Jun 2010 08:34 PM

    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

    Marco Shaw (MVP)User is Offline
    Veteran Member
    Veteran Member
    Posts:1643
    Avatar

    --
    23 Jun 2010 05:07 AM
    I'm not familiar with this "tag field". Can you provide the exact steps to see that information?
    Marco

    *Microsoft MVP - Windows PowerShell
    https://mvp.support.microsoft.com/profile/Marco.Shaw
    *Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
    *Blog - http://marcoshaw.blogspot.com
    phillblUser is Offline
    New Member
    New Member
    Posts:9
    Avatar

    --
    23 Jun 2010 06:59 PM
    Hi, Thanks for the reply. The tag field is seen in the Vitual Machine Manager application.

    Lauch virtual machine manager > right click a virtual server > properties & under the general tab there is a Tag field.

    This maybe not possible i am not sure, i would also like to be able to do it with just servers names, as long as we can pick and choose which machine we save/pause.

    Thanks
    Marco Shaw (MVP)User is Offline
    Veteran Member
    Veteran Member
    Posts:1643
    Avatar

    --
    23 Jun 2010 07:05 PM
    Oh... You must be referring to System Center! I was looking in the Hyper-V manager.

    I could try to either install the product or see if any pals of mine can give me access of some kind.

    Just providing a list of names would certainly be easy enough.

    Your choice...
    Marco

    *Microsoft MVP - Windows PowerShell
    https://mvp.support.microsoft.com/profile/Marco.Shaw
    *Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
    *Blog - http://marcoshaw.blogspot.com
    phillblUser is Offline
    New Member
    New Member
    Posts:9
    Avatar

    --
    24 Jun 2010 04:01 PM
    hi Marco, again, thanks for the reply. if you have time and you dont mind then please yes take a look at the Vitrual Machine Manager.
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    25 Jun 2010 02:31 AM
    • Accepted Answer
    How about:

    Get-VM | Where-Object {$_.Tag -eq 'pause'} | Suspend-VM

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    phillblUser is Offline
    New Member
    New Member
    Posts:9
    Avatar

    --
    28 Jun 2010 08:30 PM
    hi shay, thats fantastic. Works great. Thats for your help.

    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer