32 bit Powershell: Use the ServerManager module?

Kyle picture Kyle · Oct 1, 2012 · Viewed 10k times · Source

I'm working with a 32 bit application that can run powershell snippets. I need to load the ServerManager module, which I would normally do with:

Import-Module ServerManager

But I get this error:

The specified module 'ServerManager' was not loaded because no valid module file was found in any module directory.

I assume, this is because the ServerManager module does not exist in the 64 bit modules directory, so I have tried the following:

Import-Module "C:\Windows\sysnative\WindowsPowerShell\v1.0\Modules\ServerManager"

But now I get the error:

Import-Module : Cannot load Windows PowerShell snap-in C:\Windows\assembly\GAC_MSIL\Microsoft.Windows.ServerManager.PowerSh
ell\6.1.0.0__31bf3856ad364e35\Microsoft.Windows.ServerManager.PowerShell.dll because of the following error: Unable to load
 one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Loader Exceptions: 

Could not load file or assembly 'Microsoft.Windows.ServerManager, Version=6.1.0.0, Culture=neutral, PublicKeyToken=31bf3856
ad364e35' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.Windows.ServerManager, Version=6.1.0.0, Culture=neutral, PublicKeyToken=31bf3856
ad364e35' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.Windows.ServerManager, Version=6.1.0.0, Culture=neutral, PublicKeyToken=31bf3856
ad364e35' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.Windows.ServerManager, Version=6.1.0.0, Culture=neutral, PublicKeyToken=31bf3856
ad364e35' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.Windows.ServerManager, Version=6.1.0.0, Culture=neutral, PublicKeyToken=31bf3856
ad364e35' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.Windows.ServerManager, Version=6.1.0.0, Culture=neutral, PublicKeyToken=31bf3856
ad364e35' or one of its dependencies. The system cannot find the file specified.
At line:1 char:14

Any suggestions on how I could use the ServerManager module from within 32 bit powershell? Or another suggestion on how I could install the 'Desktop Experience' feature on Server 2008 R2 (without using the UI)?

Answer

x0n picture x0n · Oct 2, 2012

Your only real choice here is to spawn a 64 bit instance of powershell.exe to process your server manager commands. Because the parent process is 32 bit, you'll have to use the same %windir%\sysnative trick to launch powershell.exe.

%windir%\sysnative\windowspowershell\v1.0\powershell.exe 
     -command '& { ipmo servermanager; add-windowsfeature foo }'

(wrapped for clarity)