MngVMs
A tool to help in the bulk management of virtual
machines.
Currently a single mngvms.exe however this will be
expanded to for full GUI over time. Updates will be posted shortly.
Mngvms.exe focuses on shutting down VMs and starting them in a set order with the
ability for certain VMs to shutdown/startup together and only move on to the next VMs
once the complete group had shutdown/started. 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
for both startup and shutdown. When performing a 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 and they are started top down.
If you have entries in the file you don't want to act on you can comment them
out with the ' character.
Below is my configuration file (vmlist.txt)
savdaldc10|savdalbfs01.savilltech.net|60|60|1|20
savdaldc11|savdalbfs01.savilltech.net|60|60|1|0
savdalrodc01|savdalbfs01.savilltech.net|60|60|1|0
savdalfs01|savdalbfs01.savilltech.net|60|60|1|0
savdalts01|savdalbfs01.savilltech.net|60|60|1|0
savdalom01|savdalbfs01.savilltech.net|60|60|1|0
savdaldpm01|savdalbfs01.savilltech.net|60|60|1|0
savdalex10|savdalbfs01.savilltech.net|60|60|1|W
savdalscvmm|savdalbfs01.savilltech.net|60|60|1|0
Savdalcm01|savdalbfs01.savilltech.net|60|60|1|0
Savdalappv01|savdalbfs01.savilltech.net|60|60|1|0
Savdalcb01|savdalbfs01.savilltech.net|60|60|1|0
Savdalync01|savdalbfs01.savilltech.net|60|60|1|0
'Savdalwss10|savdalbfs01.savilltech.net|60|60|1|0
Savdalsm01|savdalbfs01.savilltech.net|60|60|1|0
savdalsmdw01|savdalbfs01.savilltech.net|60|60|1|0
Savdalclient.savilltech.net|savdalbfs01.savilltech.net|60|60|1|0
Savdalclient2.savilltech.net|savdalbfs01.savilltech.net|30|60|1|0
Savdalclient3.savilltech.net|savdalbfs01.savilltech.net|30|60|1|0
Savdalclient4.savilltech.net|savdalbfs01.savilltech.net|30|60|1|0
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 starts/stops all the VMs in the
group at the same time and only after all in the group have been actioned 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 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 fourth number is used during startup and
basically allows some extra time to be added after the VM has detected a
heartbeat to allow other services to complete starting before moving on. This
would be useful for a SQL VM and maybe adding a 2 minute (120 second) delay
before continuing.
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>|<extra start delay or W to wait full start time allowed>
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:
mngvms.exe <configuration file> <start|stop|restart> <group logic use: 0 no, 1 yes> <feedback
level: 1 silent, 2 normal, 3 also log file>, e.g.
mngvms.exe vmlist.txt restart 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|0, e.g.
' listvms.vbs
' John Savill 5/19/2011
'
For count = 0 To (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)
For Each VM In arrVMs
WScript.StdOut.WriteLine VM.ElementName & "|" & strHVServer & "|60|60|1|0"
Next
Next
|