After reading Tim Anderson’s blog article (here) on his installation of Hyper-V Server 2008 R2 I glibly added a comment that R2 now includes PowerShell 2.0 for local management of virtual machines using PowerShell scripts. Of course, I hadn’t actually tried this before commenting ….
Why would you want to use scripting on Hyper-V Server 2008 R2
If you have never installed Hyper-V Server 2008 R2 you may not realise the limited options provided by the local management tool. Based on Windows Server 2008 R2 Server Core there is no Windows Explorer and none of the standard user interface components for configuration. Instead the Hyper-V team provide a simple menu which supports the configuration steps required to allow remote management of the server using the Hyper-V Manager MMC snap-in (available for Vista, Windows 7 and Windows Server 2008).
The real ‘local’ management tool is that old fashioned item, the command prompt,
So, if you aim to manage Hyper-V Server 2008 R2 you should get used to command line tools and commands, which means having access to a scripting system like PowerShell provides a route for local management of virtual machines without requiring the Hyper-V Manager on a separate client machine.
No PowerShell by default
As stated above, Hyper-V Server 2008 R2 is based on Windows Server 2008 R2 Server Core, and it is this update that included support for .NET framework and PowerShell scripting. Quite correctly server core locks down all functionality until it is enabled/installed. PowerShell is one of the items that are not installed by default.
First installation attempt
So I did a quick Google/Bing for Enabling PowerShell on Hyper-V Server 2008 R2 and got to this blog article (here) on the highly useful Virtual PC Guy’s blog. I followed the steps. No joy.
Hold on – doesn’t PowerShell required .NET Framework?
I did a directory search, dir c:\windows\*powershell*.exe /s, to see if the directory path had changed, but instead of finding a PowerShell installation, I found a list of files in a directory called c:\windows\winsxs. This directory appears to contain all the install packages for server core, and as well as PowerShell it included .NET framework installations.
This was the ‘lightbulb’ moment I was searching for. PowerShell probably won’t install because I the .NET Framework is not installed. A big more of Google/Bing and I found the following article on Window Server 2008 R2 Server Core, on MSDN, http://code.msdn.microsoft.com/r2core/Wiki/View.aspx?title=Home&version=8
I ran the command oclist to list all the installed options,
There, right in the middle was PowerShell being a child node of NetFx2 (.Net Framework 2.0) which suggested a dependency. So I ran the following installation commands
start /w ocsetup NetFx2-ServerCore
start /w ocsetup MicrosoftWindowsPowerShell
After that, I had PowerShell installed,
To run it I just cd‘d to c:\windows\system32\WindowsPowerShell\v1.0 and typed powershell
Alternatively once you reboot the system, the PowerShell directory will be placed in the search path and you can just type powershell in any directory to access the PowerShell command prompt.
Next steps …
In a post next week I’ll demonstrate how to use the PowerShell Management Library for Hyper-V available on codeplex (http://pshyperv.codeplex.com/) on Hyper-V Server 2008 R2 to list running virtual machines, start and stop virtual machines and do useful admin stuff like mount/dismount VHD drives.