With the pending release of Windows Server 8 and Hyper-V 3.0, Microsoft has made it clear that PowerShell v3 will...
become the underlying standard for administrating its server platforms. The new PowerShell v3 includes a slew of new cmdlets for managing and automating the server and desktops versions of Windows 8, including Hyper-V, which already has more than 1,000 cmdlets and counting.
More on PowerShell in Hyper-V
Top Hyper-V PowerShell cmdlets for basic tasks
Hyper-V management with PowerShell: Monitoring and testing
In the past several years, Microsoft has increasingly turned to the PowerShell scripting language to provide an operational framework for many of its products, most notably Exchange 2010. Going forward, it appears that PowerShell v3 will be the foundational element for all of the Hyper-V administration tasks and commands.
Microsoft insiders say that eventually all of the Microsoft administrative tools with a graphical user interface will actually execute PowerShell code underneath. For example, you will be able to completely manage Windows Server roles, such as Hyper-V, through the Systems Center family, which will run PowerShell cmdlets under the hood.
In the immediate future, however, you can use PowerShell v3 to install and configure Hyper-V from the command line. No GUI necessary.
PowerShell v3 in Hyper-V 3.0
To get rolling, download the Windows Server 8 beta code via a MSDN or TechNet subscription. Next, install it as a virtual machine in your hypervisor of choice.
My Hyper-V 3.0 test build
I use VMware Workstation and Fusionextensively, and installing the beta code into them was a cinch. The latest version of VMware Workstation 8 even has a predefined machine type for Windows Server 8, which is listed as experimental. I was also able to download the Windows Server 8 virtual disk build -- a pre-made .vhd image -- and import it into an existing Hyper-V server without any issue.
Once Windows Server 8 is installed, start the installation of the Hyper-V role with the following PowerShell command:
Add-WindowsFeature Hyper-V –Restart
(I know it says feature in the command, but it is actually a role.)
Then, you need to import the Hyper-V PowerShell module:
Running PowerShell v3 cmdlets in Hyper-V 3.0
Now you’re ready to rock! Go ahead and get a listing of all the cmdlets available for administrating Hyper-V:
Get-Command –Module Hyper-V –Verb
Once I load a new module into PowerShell, I like to run the following command to get a list all the properties for certain objects:
Get-VM | Get-Member –MemberType Property
Pretty interesting and informative display, huh? Now you can see all the properties, old and new -- such as information on virtual hard drives, memory assigned, processor count -- that you can query against using various PowerShell cmdlets.
Here are just a couple of interesting new commands that I have found. Snoop around a bit and find some more.
- Enable-VMMigration #enable migrations
- This cmdlet enables virtual machine migration between Hyper-V hosts.
- Add-VMMigrationNetwork #add subnets to the VM migration settings
- By executing this cmdlet, you can add subnets to the migration network in Hyper-V. It allows for more flexibility among the hosts that have migration enabled.
New-VMReplicationAuthorizationEntry #add authorization entry for a VM
This cmdlet creates a new authorization entry that contains the new Hyper-V host (or allowed primary server) as well as its corresponding replica storage in the Hyper-V cluster
The drawbacks to PowerShell v3
While you’re getting a bunch of new Hyper-V cmdlets in PowerShell v3, it’s also important to note one drawback, as of the beta preview. The new cmdlets for Hyper-V 3.0 cannot manage older version of Hyper-V. This is a pretty big issue with administrators who will now have to segregate their scripts, depending on which version of Hyper-V they are managing, at least until they can upgrade all of their hosts.
The incompatibility between Hyper-V 3.0 and previous versions is confusing and inconvenient. But, as we all know, it’s not an uncommon requirement of software vendors. For administrators with older versions of Hyper-V, you should download the PowerShell Library for Hyper-V from CodePlex.
Dig Deeper on Server hardware and virtualization