Import-Module ServerManager Import-Module : 未能加载指定的模块“ServerManager”,由于在任何模块目录中都没有找到有效模块文件..

操做系统: Windows server 2008 R2(64位)shell

C:\Windows\System32\WindowsPowerShell\v1.0\Modules 下有ServerManager的东东,但是仍是找不到。ui

解决这个问题,须要2步:spa

一、Powershell中的执行策略(Execution Policy)

缘由一个是由于Powershell默认的执行策略是Restricted,便可以运行单条命令,但不能运行脚本,包括格式和配置文件 (.ps1xml)、模块脚本文件 (.psm1) 和 Windows PowerShell 配置文件 (.ps1)、以及.bat文件。 解决方案是把执行策略改得宽松一点,好比RemoteSigned或者Unrestricted。在Powershell中运行如下命令便可: Set-ExecutionPolicy RemoteSigned 或 Set-ExecutionPolicy Unrestricted或-ExecutionPolicy RemoteSigned操作系统

二、64位操做系统和32位操做系统的关系.net

CMD ,64位操做系统有两个。一个是:C:\Windows\System32\CMD.exe(这个是64位的CMD,尽管名字叫System32);一个是C:\Windows\SysWOW64\CMD.exe(这个是32位的CMD.SysWOW64文件夹下的东西是64位操做系统为运行32位的应用程序而准备的)。rest

但是我编译生成的.exe是32位的,经过Setup Factory的File.Run(...)或者Shell.Execute(...),会调用C:\Windows\SysWOW64\CMD.exe(32位的CMD)。而ServerManager Module只有64为才有server

因此改成编译成64位的就行了。xml

 

附(运行的脚本):blog

InstallDotNET.bat博客


@echo on

cd C:\Windows\System32\WindowsPowerShell\v1.0
powershell -ExecutionPolicy "UnRestricted" -File C:\InstallDotNET.ps1

InstallDotNET.ps1

import-module ServerManager
Add-WindowsFeature NET-Framework
exit


 

特别感谢(他们的博客最终给了我解决方案):

http://www.tuicool.com/articles/RvqqI3

http://blog.csdn.net/leon110/article/details/6203380

备注:

应用场景,经过Setup Factory调用PowerShell的脚本

相关文章
相关标签/搜索