Operating system: Windows Server R2 (64-bit)
C:\Windows\System32\WindowsPowerShell\v1.0\Modules under the Servermanager, but still can not find.
To solve this problem, it takes 2 steps:
1. Implementation strategy in PowerShell (execution policy)
One reason is that the default execution policy for PowerShell is restricted, which means that you can run a single command, but you cannot run scripts, including format and configuration files (. ps1xml), module script files (. psm1), and Windows PowerShell profiles (. PS1), and. bat files. The solution is to change the execution strategy to a looser point, such as remotesigned or unrestricted. Run the following command in PowerShell: Set-executionpolicy remotesigned or set-executionpolicy unrestricted or-executionpolicy RemoteSigned
2, 64-bit operating system and 32-bit operating system relationships
CMD, there are two 64-bit operating systems. One is: C:\Windows\System32\CMD.exe (this is the 64-bit CMD, although the name is System32); one is C:\Windows\SysWOW64\. CMD.exe (This is something under the 32-bit Cmd.syswow64 folder is a 64-bit operating system prepared for running 32-bit applications).
But I compiled the generated. EXE is 32-bit, through the Setup Factory File.run (...) or Shell.execute (...), the C:\Windows\SysWOW64\CMD.exe (32-bit CMD) is called. And the Servermanager module is only 64.
So it would be better to compile it into 64 bits instead.
Attached (running script):
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
Special thanks (their blog finally gave me the solution):
Http://www.tuicool.com/articles/RvqqI3
http://blog.csdn.net/leon110/article/details/6203380
Import-module Servermanager import-module: Failed to load the specified module "Servermanager" because no valid module file was found in any module directory ... (script that calls PowerShell via Setup factory)