我正在使用可以运行powershell代码段的32位应用程序。我需要加载ServerManager
模块,我通常会这样做:
Import-Module ServerManager
但是我收到了这个错误:
未加载指定的模块“ServerManager”,因为在任何模块目录中找不到有效的模块文件。
我认为,这是因为64位模块目录中不存在ServerManager模块,所以我尝试了以下内容:
Import-Module "C:\Windows\sysnative\WindowsPowerShell\v1.0\Modules\ServerManager"
但现在我收到了错误:
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
有关如何在32位PowerShell中使用ServerManager模块的任何建议?或者关于如何在Server 2008 R2上安装“桌面体验”功能(不使用UI)的另一个建议?
答案 0 :(得分:3)
这里唯一真正的选择是生成一个64位的powershell.exe实例来处理你的服务器管理器命令。由于父进程是32位,因此您必须使用相同的%windir%\sysnative
技巧来启动powershell.exe。
%windir%\sysnative\windowspowershell\v1.0\powershell.exe
-command '& { ipmo servermanager; add-windowsfeature foo }'
(为清晰起见)
答案 1 :(得分:1)
除了x0n的回答..阅读此内容 http://karlprosser.com/coder/2011/11/04/calling-powershell-64bit-from-32bit-and-visa-versa/
它解释了为什么以及什么时候Sysnative(从32位到64位)以及何时应该使用SysWow64(64位到32位)。