Installing server roles via Powershell

(imported topic written by Bill.Ehardt)

Having troubles running a simple powershell script via software dist dashboard. The script itself is a .ps1 file, and is as follows:

Import-Module ServerManager

add-windowsfeature GPMC, AS-NET-FRAMEWORK, DESKTOP-EXPERIENCE, RDS-RD-SERVER

Powershell kicks off, but says "The specified module ‘ServerManager’ was not loaded because no valid module file was found in any module directory’.

When I log in to the server and run the script, it works fine. I’m assuming it is because I’m running as System, and not a specific user. I’ve tried to specify the full path of the module directory but that didn’t help.

Has anyone done this before, or have tips?

(imported comment written by SystemAdmin)

Hi Bill,

this may be because the powershell.exe is being launched from a 32-bit process and file-redirection kicks in to run the 32-bit powershell in SysWOW64 instead of the 64-bit one which will have the modules.

You can try launching the powershell using the

“C:\windows\sysnative\windowspowershell\v1.0\powershell.exe”

which will force it to use 64-bit.

Gary.

(imported comment written by SystemAdmin)

The registry can also be referenced. Here is an example that installs some roles. Notice the x64 registry reference. Note that we have seen some features and roles need to be installed on separate lines of a powershell overwise the install will fail. For example, installing Hyper-V and WDS simultaneously on the same line fails, but works if they are on different lines.

parameter “PowerShellexe”="{value “Path” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell” of x64 registry}"

delete __appendfile

delete ServerRoleInstall.ps1

appendfile Import-Module ServerManager

appendfile Add-WindowsFeature WDS, WDS-AdminPack

appendfile Add-WindowsFeature Hyper-V, RSAT-Hyper-V-Tools -IncludeAllSubfeature

move __appendfile ServerRoleInstall.ps1

action uses wow64 redirection false

wait “{parameter “PowerShellexe”}” .\ServerRoleInstall.ps1

(imported comment written by Bill.Ehardt)

Thanks both of you, that worked!

(imported comment written by SystemAdmin)

I know this isn’t via powershell… however consider checking into my Features project http://bigfix.me/features

I believe powershell just adds a layer of complication for something very simple. My Features content uses the dism.exe tool to detect features and a special database/fixlet generator to create install and uninstall fixlets for each feature detected. I’ve used the dism.exe tool and scanned many different versions of windows vista, 7, 8, and the various servers to give you a good complete list of available features to generate fixlets for.