SavillTechDownload areaServicesProducts Videos area


line HVManage

A tool to help in the bulk management of virtual machines.

Currently a single stopvms.exe however this will be expanded to for full start capability and a GUI. Updates will be posted shortly.

 Stopvms.exe focuses on shutting down VMs in a set order with the ability for certain VMs to shutdown together and only move on to the next VMs once the complete group had shutdown. This is useful when you have dependencies between VMs. For example in my environment I need to shutdown the VMs in a set order:

Client virtual machines -> RDS servers (like connection broker, session host) -> System Center servers -> SQL server -> Exchange Server -> Domain Controllers

I created a simple program that takes a configuration file in as input. Because a shared configuration file is used and this is shutdown we work backwards through the file so you should list the configuration file with the VM to start first at the top working down. So basically the VM you want to stop first you need at the bottom.

Below is my configuration file (vmlist.txt)

savdaldc10|savdalbfs01.savilltech.net|60|60|1

savdaldc11|savdalbfs01.savilltech.net|60|60|1
savdalrodc01|savdalbfs01.savilltech.net|60|60|1

savdalfs01|savdalbfs01.savilltech.net|60|60|1
savdalts01|savdalbfs01.savilltech.net|60|60|1

savdalom01|savdalbfs01.savilltech.net|60|60|1

savdaldpm01|savdalbfs01.savilltech.net|60|60|1

savdalex10|savdalbfs01.savilltech.net|60|60|1
savdalscvmm|savdalbfs01.savilltech.net|60|60|1

Savdalcm01|savdalbfs01.savilltech.net|60|60|1
Savdalappv01|savdalbfs01.savilltech.net|60|60|1

Savdalcb01|savdalbfs01.savilltech.net|60|60|1
Savdalync01|savdalbfs01.savilltech.net|60|60|1
Savdalwss10|savdalbfs01.savilltech.net|60|60|1

Savdalsm01|savdalbfs01.savilltech.net|60|60|1
savdalsmdw01|savdalbfs01.savilltech.net|60|60|1

Savdalclient.savilltech.net|savdalbfs01.savilltech.net|60|60|1

Savdalclient2.savilltech.net|savdalbfs01.savilltech.net|30|60|1
Savdalclient3.savilltech.net|savdalbfs01.savilltech.net|30|60|1
Savdalclient4.savilltech.net|savdalbfs01.savilltech.net|30|60|1


Notice I have some blank lines. A blank line means a new group as the utility can be told to handle VMs as groups which means it stops all the VMs in the group at the same time and only after all in the group have stopped does it move onto the next group. In my example file it would stop savdalclient2-4 and once all are stopped it would stop savdalclient, once that stopped savdalsm01 and savdalsmdw01 and so on. It performs a shutdown via the integration services and if the VM does not stop within the configured time limit (the first number) then it sends a turn off.

The second number is the time to allow to start (will be used in the start utility) and the third number tells it if its not stopped in the time limit then perform a turn off (1 yes turn off, 0 would not do anything and just leave it but move on to the next VM/group)

The first part is the name of the VM, must match exactly the name of the VM in Hyper-V manager. The second is the Hyper-V server.

<VM Name>|<Hyper-V Server FQDN>|<stop time out>|<start time out>|<turn off on shutdown timeout>

You need to ensure RemoteAdmin for WMI is enabled on the Hyper-V server and you have WMI permissions:

netsh firewall set service RemoteAdmin enable    on remote machine to enable remote WMI. Also ensure the right WMI security permissions using the Computer Management application, navigate to Services and Applications then WMI Control and under Root - Security make sure have Remote Enable for users who will be using the tool on remote Hyper-V servers.

To use just pass the name of the configuration file, 1 to use group logic or 0 to stop VMs just one at a time then the final number is the feedback, 1 for silent, 2 for normal and 3 to also create a dump file of the amount of time it took to stop each VM to file savtechvminfo_<name of host you run command from>.log:

stopvms.exe <configuration file> <group logic use: 0 no, 1 yes> <feedback level: 1 silent, 2 normal, 3 also log file>, e.g.
Stopvms.exe vmlist.txt 1 2

To help create the list of VMs you can modify the script in FAQ "Q. How can I quickly create a list of all VMs on a list of Hyper-V servers from the command line?" and change the writeline section of code to not have state and instead just end with |60|60|1, e.g.

' listvms.vbs
' John Savill 5/19/2011

'
For count = 0To (WScript.Arguments.Count-1)
    strHVServer = WScript.Arguments.Item(count)
    Set objWMIService = GetObject("winmgmts:\\" & strHVServer & "\root\virtualization") 
    Set arrVMs = objWMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem",,48)
    ForEach VM In arrVMs
        WScript.StdOut.WriteLine VM.ElementName & "|" & strHVServer & "|60|60|1"
    Next
Next

 

Last Update: Tuesday, 7th June 2011
Copyright ©2011 SavillTech Ltd. All rights reserved. Terms of use