As I recently have rebuilt my laptop to run Windows 7 RC, I decided to download and install the XenServer Powershell extensions (available here) to start evaluating them. I was going to start writing my own extension but then stumbled across the ones that Citrix has developed and figured instead of writing my own, I would post some videos pertaining to the Citrix distributed ones. As a side not, Citrix has also released the source code to the PowerShell extensions. A very cool move in my humble opinion. I believe more companies should contribute to the open source community, and props to Citrix for taking this step.
After the installation, I checked the readme and saw an important item
“3. Determine the current execution policy, like this:
PS> Get-ExecutionPolicy
If the current policy is Restricted, then you need to set it to
RemoteSigned, like this:
PS> Set-ExecutionPolicy RemoteSigned
You should understand the security implications of this change. If you
are unsure, see Microsoft's documentation on the matter:
PS> Get-Help about_signing
If the current policy is AllSigned, then this will work, but will be
very inconvenient. You probably want to change this to RemoteSigned,
as above.
If the current policy is Unrestricted or RemoteSigned, then this is
compatible with XS-PS, so there is nothing to do.”
After adhearing to the above documentation ;), lets go ahead and run the XenServer Powershell Snapin from the start menu.
The resulting output from powershell is the below screenshot. Basically Powershell is telling us that it cannot find the XenServerPSSnapIn snapin, which typically means that the xenserverpssnap dll did not get registered properly during the installation. At least that is the initial theory :)
Maybe we need to run the installer as administrator, sometimes I forget to do this, but I thought this might be an issue so lets make sure and reinstall as admin. Well, that didnt work in my case so on to the original theory.
To make sure that this is indeed the case, lets fire up Microsoft Orca (MSI Editor tool) and edit the XenServerPSSnapIn-5.0.0-3.msi to see if we can find a custom action or something that takes care of the registration process. After searching around within the MSI indeed there is a custom action that is supposed to register the xenserver snapin on the machine as shown below.
To further confirm that the snapin did not get registered during the installation process let check the registry. You can locate all registered PowerShell snapins by checking the following key
HKEY_LOCAL_MACHINESOFTWAREMicrosoftPowerShell1PowerShellSnapIns
Side Note: If your developing PowerShell snapins using C#/VB.Net once you compile your snapin dll you will need inform PowerShell that it is installed on the the machine and you want to load it into PowerShell. This is a two step process.
Step 1: use the installutil.exe utility to register the DLL onto the system the syntax is something similar to the following
%windir%Microsoft.NetFrameworkv2.0.50727installutil.exe [full path to your dll]
Step 2: once you have registered your dll on the system you need to add it to Powershell. You can do this by issuing the Add-PSSnapIn command from within powershell, like the following
Add-PSSnapIn –name [Your SnapIn Name]
So, now we know what the problem is we can work on fixing it so we can start using the SnapIns :)
The first step in the process is to register the snapin DLL on the the machine. Check out the side note above. We can achieve this by issuing the following command from within powershell. (Note: You will need to run PowerShell as administrator, especially if you are running on Windows 7).
C:WindowsMicrosoft.NETFramework64v2.0.50727InstallUtil.exe [Path To XenServer DLL]XenServerPSSnapIn.dll
Once issuing this command you should see something like the following screenshot.
Now, from here you should be able to execute the XenServer Powershell Snapin from the start menu, and you will get the resulting powershell window ,with the snapin registered and ready to go, like the following. As you can see we have connected to out test XenServer
To further show that the the snapin is indeed loaded, we can issue the command Get-PSSnapin and it will show that the XenServer snapin is loaded.
Now, if you want to load the snapin into a regular powershell window, you would need to issue the Add-PSSnapIn command and that will load up the snapin for use within the current powershell window, like the following
Add-PSSnapin XenServerPSSnapIn
This will load the snapin and make the commands available for you to use.
Now, at this point, I’m not sure why the install did not properly register the XenServerSnapin.Dll on my Windows 7 RC system, but I am trying to do some further research on this and as soon I find out more info I will post it here. I hope this post helps out.
As always you can reach me through comments on here, follow me on twitter (http://www.twitter.com/johnmcbride) or friend me on FaceBook.