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!
Great scripts. Do you have one for export and import?
LikeLike
Thank you!
Very helpful scripts.
LikeLike
Any scripts to take a snapshot and revert back to a snapshot?
LikeLike
Thank you for your job.
Is there any scripts can create a virtual system?
LikeLike
Here you go…
http://blogs.msdn.com/b/virtual_pc_guy/archive/2008/05/28/scripting-vm-creation-with-hyper-v.aspx 🙂
LikeLiked by 1 person
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?
LikeLike
Hi,
Can any one reply to my abov query?
LikeLike
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…
LikeLike
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
LikeLike
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.
LikeLike
Hi,
Any idea how you can rename a snapshot using rootvirtualizationv2?
LikeLike
Hard resetting doesn’t work. I try reset from c#, but nothing here
LikeLike
Excellent post. I was checking constantly this blog and I am impressed!
Very useful information particularly the last part 🙂 I care for such info a lot.
I was seeking this certain information for a long time.
Thank you and good luck.
LikeLike
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.
LikeLike
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 ?
LikeLike