我正在使用一个可以运行powershell片段的32位应用程序。我需要加载 ServerManager 模块,我通常会用它来做:

Import-Module ServerManager

但我得到这个错误:

未加载指定的模块'ServerManager',因为在任何模块目录中都找不到有效的模块文件。

我假设,这是因为ServerManager模块不存在于64位modules目录中,所以我已经尝试了以下内容:

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模块的任何建议?或者关于如何在Server2008R2上安装"桌面体验"功能的另一个建议(不使用UI)?

有帮助吗?

解决方案

您唯一真正的选择是生成powershell的64位实例。exe来处理您的服务器管理器命令。因为父进程是32位的,所以你必须使用相同的 %windir%\sysnative 招启动powershell。exe的。

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

(包装为清晰起见)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top