Hyper-V and PowerShell: Part 3, Loading the Modules

The PowerShell Modules that I have been using come from the Codeplex Site, I came across them recently but to be honest I need not find it that straight forward to install as first. But when I need, life was easier within minutes.

 

Then you may run into errors with Trusted Policy if so then follow this set of instructions,

To set RemoteSigned as the execution policy, run the following command.
> Set-ExecutionPolicy RemoteSigned
Lets try importing now.
PS C:\Windows\system32> Import-Module hyperv

Import-Module : The following error occurred while loading the extended type data file:
Microsoft.PowerShell, C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Hyperv.psd1 : File skipped because it was already present from “Microsoft.PowerShell”.
No go even now 🙂 . When we try to execute any IIS cmd-let like get-website we will get an not recognised cmd-let error. Here’s how to solve the entire situation.

Close the PowerShell window and re-open it with elevated privileges and enter Get-ExecutionPolicy:
> Get-ExecutionPolicy
RemoteSigned
That’s good news … no more Restricted. Lets try importing the IIS module yet again.
>Import-Module hyperv

No error. Success!

The commands described below are implemented in the form of a PowerShell version 2 Module which is distributed as a single ZIP file, from http://PShyperV.codeplex.com with this document being made available separately.
A previous version was implemented for version 1 of PowerShell but this version and remains available on codeplex. The old version will work on PowerShell V2, but the new version will not work on PowerShell V1. Both versions work with the original release of Hyper-V and the R2 release.

The installation process consists of placing the PowerShell files into a suitable folder.
The module is then imported into a PowerShell session using the command Import-Module <path\>Hyperv.psd1
If no path is specified, PowerShell uses the system environment variable PSModulePath and examines each folder it references to find a folder using the name specified for the module, containing a manifest file of the same name. So, for example if you place the files into the c:\users\yourID\documents\windowsPowershell\modules\HyperV you can just issue the command install-module HyperV
(Install module can be shortened to IPMO)

The zip file includes a simple Install.cmd file which will make the following changes
  ? Install PowerShell on Hyper-V Server or Windows Server 2008-R2 Core installations. This produces a harmless error on full installations of Server 2008 , which can be ignored.
  ? Create a folder under program files and add this folder to the PSModulePath environment variable
  ? Place the files in a subfolder of this a folder
  ? Set registry settings to give an ideal PowerShell console window and to allow PowerShell to run unsigned scripts.

You may do any or all of these things manually, and good practice says you should review a registry file before allowing it to change your system. The Scripts are not signed and if you wish to implement a policy of signing scripts you should verify the script for yourself and then sign it.
This build includes a menu – similar to the PowerShell configurator found on codeplex at http://psconfig.codeplex.com/ you can launch the menu with the command Show-Hypervmenu
Alternatively when the module has been imported, you can discover its commands by entering the commands
get-command -module HyperV
or
get-command -module Hyperv| get-help | format-table name,synopsis -auto
Finally get-help Command-Name –full will give you the online help for a command

Leave a Reply