Script to Turn Off all Hyper-V VMs?

답변됨 Script to Turn Off all Hyper-V VMs?

  • Thursday, October 30, 2008 7:02 PM
     
     
    Need a script to Turn Off all the VMs running on a server with the Hyper-V role enabled?
    Tony Soper

All Replies

  • Thursday, October 30, 2008 7:04 PM
     
     Answered Has Code
    John Kelbley provides one, you can leave feedback here or contact johnkel@microsoft.com:

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\virtualization")
    Set vmcollecion = objWMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem",,48)

    ' loop through all instances in collection
    For each vm in vmcollecion
     RequestReturn = vm.RequestStateChange(3)
    Next



    Tony Soper
    • Edited by tonyso Thursday, October 30, 2008 7:04 PM has code
    • Marked As Answer by tonyso Thursday, October 30, 2008 7:04 PM
    •  
  • Monday, November 24, 2008 1:26 PM
     
     
     You can also check my blog on Hyper-V  and PowerShell.
    I have some examples using PowerShell coding against WMI

    EnjoY!
    /Dung

    http://dungkhoang.spaces.live.com