Manage Hyper-V Virtual machines using WMI and VBS scripts

Today I was working on how to manage Hyper-V virtual machines using WMI.
This VBS scripts can be modified to suit your needs…
Each script takes one argument “machine name”:

listvm.vbs – display all virtual machines on Hyper-V – this script will create a TXT file (you should edit path and filename inside the script) with all virtual machines that are on Hyper-V host. It will print names of the machines and current state (Running, Off, Saved)

sortvm.vbs – this script alphabeticaly sorts list of virtual machines (you should edit path and filename inside the script)

startvm.vbs – usage: startvm.vbs “Name of your virtual machine” – this script will start the virtual machine

stopvm.vbs – usage: stopvm.vbs “Name of your virtual machine” – this script will turn of (dirty!) your virtual machine

shutdownvm.vbs – usage: shutdownvm.vbs “Name of your virtual machine” – this script will shut down your virtual machine if it is Integration Services aware – it will signal/notify guest operating system to initialize shutdown procedure. It works only on machines that support Hyper-V Integration services.

hardresetvm.vbs – usage: hardresertvm.vbs “Name of your virtual machine” – this script will reset (dirty!) your virtual machine

savestatevm.vbs – usage: savestatevm.vbs “Name of your virtual machine” – this script will save and turn off your virtual machine

I have compiled this scripts using resources regarding Hyper-V and WMI
http://msdn.microsoft.com/en-us/library/cc136992(VS.85).aspx
http://blogs.msdn.com/virtual_pc_guy/

Enjoy, WMI power!

15 thoughts on “Manage Hyper-V Virtual machines using WMI and VBS scripts

  1. vin

    Very helpful.

    Is there a way to get Virtual Machine Volume labels, Number of NICs, Disk provisioning types, number of CPUS, number of disks, RAM size in MB?

    Like

    Reply
  2. sHANE

    Thanks for this post! Scripts worked great, you would think that microsoft would have had these built into the server software to start and stop vms from the command line…

    Like

    Reply
  3. Satyendra

    Hey awsome script they are , i was searching too much for this thanx
    I want one more script pls provide that one ,script for making new virtual machine and adding vhd in that pls help me for that
    Thnaks and Regards

    Like

    Reply
  4. Mike

    Love the scripts,

    I’m building an app to run these via over windows network to other hyperv hosts. Having a little trouble, is anyone having success doing anything like this ? I can get it all working from the app, running the command locally, but accross the network, not so much luck.

    Like

    Reply
  5. Ken C

    Nice scripts. Thank you for posting.
    I will note I had to use WbemScripting.SWbemLocator to connect to my servers so I could use a username/password.

    Like

    Reply
  6. Baha

    Hello,

    can anyone help about how to monitor the Hyper-v replication health in windows 2012 R2 ?

    do you have a vbs script to do that ?

    Like

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s