How to enable PowerShell in Hyper-V Server 2008 R2

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).

Hyper-V Server Local Management Tool

The real ‘local’ management tool is that old fashioned item, the command prompt,

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.

First installation attempt

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,

OCList output

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,

Installation Complete

To run it I just cd'd to c:\windows\system32\WindowsPowerShell\v1.0 and typed powershell

PowerShelll command prompt

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.

Print | posted on Wednesday, November 4, 2009 9:00 PM

Comments on this post

# re: How to enable PowerShell in Hyper-V Server 2008 R2

Requesting Gravatar...
En esta dirección hay un artículo muy interesante y detallado sobre como instalar y configurar de Hyper-V Server R2, echadle un vistazo.

http://www.malagahabla.com/instalaci%c3%b3n-y-configuraci%c3%b3n-de-microsoft%c2%ae-hyper-v%e2%84%a2-server-2008-r2.aspx
Left by Adia on Jun 10, 2010 11:17 PM

# re: How to enable PowerShell in Hyper-V Server 2008 R2

Requesting Gravatar...
Alternatively:

dism.exe /online /enable-feature /featurename:NetFx2-ServerCore
dism.exe /online /enable-feature /featurename:NetFx3-ServerCore
dism /online /enable-feature /featurename:MicrosoftWindowsPowerShell
Left by ivanbrug on Sep 13, 2011 12:46 PM

Your comment:

 (will show your gravatar)