Month: March 2008

Script wrapper to install Hyper-V role based on OS flavor

As a part of my experiments with Hyper-V, I install many systems with Hyper-V role. I have a automated way to perform OS installs and wanted to enable the Hyper-V role as well at the end of it. This VBScript wrapper checks the OS flavor (Windows Server 2008 Full OS or Core) and enables Hyper-V role automatically at the end of OS install. Here are couple of checks I perform in this script 1. Make sure that the OS architecture is AMD64 2. Checks if the OS is Server Core and branches out to different command method For full OS installs, Servermanagercmd.exe is used and OCsetup for the Server Core installs. Remaining script is self explanatory. You can download the script here.

Script Update: Right click to Mount & Dismount Hyper-V VHD

Updated scripts are here I have updated the script I posted sometime back. I have put some error checks to make sure that you don’t try to mount a VHD which is already mounted or in use. Also, this script will mount only the “real” VHDs. In the unmount context, I just have a check to if the unmount is successful or not. If not success, I am just returning a message to the user. You can download the update script here Update (3/29) You can even use this script at the command prompt to mount or dismount VHD. To mount, Cscript VHDMount.vbs  mount vhdpath To dismount, Cscript VHDmount.vbs dismount vhdpath

VBScript to parse GetVirtualHarddiskInfo() output

As mentioned in my earlier post, Msvm_ImageManagementService.GetVirtualHarddiskInfo() doesnot return the embedded instance of Msvm_VirtualDiskInfo class. Instead, it just returns one big string as shown here instance of Msvm_VirtualHardDiskInfo {Type = 3;FileSize = 2405406208;MaxInternalSize = 32212254720;InSavedState = TRUE;InUse = FALSE;}; Parsing this for individual values of Type, FileSize, MaxInternalSize, InSavedState and InUse will be a very tedious job if you have no clue about using regular expressions. Regular expressions could be quite intimidating because of their cryptic nature. Many people don’t even look at RegEx because of the same reason. I was also in the same state until last week. But, when I came across this limitation of GetVirtualHarddiskInfo(), I got a copy of Beginning Regular Expressions by Andrew Watt and started learning regular expressions. I just completed the reading and here is the outcome of what I just learned. This script parses the output of Msvm_ImageManagementService.GetVirtualHarddiskInfo() and gets the individual value. As you can see in the script, the regular expression I had used is (?:Type = )([A-Za-z0-9]*)(?=\;). The only capturing group in this RegEx …


I couldn’t think of a better title than this for the post. I want to write about a limitation with this WMI interface. This method can be used to get the information pertaining to a VHD under Hyper-V. This, when used, queries Msvm_VirutalDiskInfo class and returns a single large string containing the information about the VHD. Output on your system will look something like instance of Msvm_VirtualHardDiskInfo {Type = 3;FileSize = 2405406208;MaxInternalSize = 32212254720;InSavedState = TRUE;InUse = FALSE;}; This is not the exact embedded instance of Msvm_VirutalDiskInfo. You will have to parse the above string manually to get the required information.

Right click to Mount & Dismount Hyper-V VHD

Updated scripts are here Virtual Server 2005 had a tool to mount and unmount VHD files. MS, so far, has not given this tool with hyper-V. However, they published WMI interfaces for doing the same. So, here is a small script that enables Mount/Unmount options in the context menu when you right-click on a .VHD file. I am currently not handling any errors. This will fail if you try to mount / unmount a VHD in use. I am looking at WMI interfaces to understand how I can put some checks in to the script. To use this script (Works only on LH system with Hyper-V or any system that has Hyper-V WMI interfaces), 1. Unzip the contents to desktop 2. Copy vhdmount.vbs to c:\ 3. Double-Click on HV-Reg.reg and export the contents to Windows Registry 4. Right-Click on a .VHD file and you can see mount and dismount options You can download the script here

Introverted iNtuitive Thinking Perceiving – INTP

I underwent MBTI training yesterday and I was reported to be INTP. The Myers-Briggs Type Indicator (MBTI) is a personality questionnaire designed to identify certain psychological differences according to the typological theories of Carl Gustav Jung as published in his 1921 book Psychological Types (English edition, 1923). The original developers of the indicator were Katharine Cook Briggs and her daughter, Isabel Briggs Myers, who initially created the indicator during World War II, believing that a knowledge of personality preferences would help women who were entering the industrial workforce for the first time identify the sort of war-time jobs where they would be “most comfortable and effective.” Coming to my type, INTPs are pensive, analytical folks. They may venture so deeply into thought as to seem detached, and often actually are oblivious to the world around them. You can read more about INTP here. My self-estimate and psychometric tests cleared showed that I am INTP. Many other folks on the team had different results leading to lot of confusion about their type. There is a need …

Handy script to manage guests on a Server Core Hyper-V host

I wrote this for my own convenience and it may be useful to others also. This is a simple script that uses new WMI interfaces provided for managing Hyper-V. This script can start or shutdown or save state of all VMs on a host. This is useful especially on a ServerCore system with Hyper-V and with no remote management tools. You can download the script Here This script is self-explanatory and it provides usage help as well. Couple of points about the script I have put a conditional check to see if the VMs caption is “Microsoft Virtual Computer System”. Without this check the script will list parent partition details also and try to perform the same action requested. Also, VM shutdown cannot be performed by just calling the RequestStateChange method. Calling this method with a parameter 3 will result in improper shutdown. WMI provides InitiateShutdown method for this purpose. This will make sure the guest shuts down cleanly Feel free to comment