Server 32 and server 64 else if?

I am working on writing a script to install windows features on both server 2008 and server 2008 R2 seeing as all of our server 2008 boxes should be 32 bit i am attempting to control the way the script runs via the return of $osarchitecture though I seem to be having some troubles. Forgive me as I am relatively new to powershell. Here is what I have so far?

$erroractionpreference = “SilentlyContinue”
$servers = Get-Content -path c:\SCCMMangerScript\CSV\SCCMServers.csv
foreach ($server in $servers){
} $OS = (Get-WmiObject -computername $server -class Win32_OperatingSystem -Property Version,osarchitecture ).caption
if ($os = “64-bit”) {

$session = New-PSSEssion -Computername $server
Enter-PSSession -ComputerName $server
Invoke-Command -session $session {Import-Module Servermanager}
Invoke-Command -session $session {Add-Windowsfeature Web-Mgmt-Compat | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Metabase | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Filter | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Ext | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-WMI | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Windows-Auth | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature BITS | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature RDC | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Exit-PSSession}

} #end if

elseif ($os = "32-Bit") {

Server 2008 32Bit (this is the one I have been having trouble with as you can see a lot has to happen for it to become a DP correctly.)

#Set-ExecutionPolicy Unrestricted
#list of 32bit servers
$servername = ‘xyz still need to change to pull name automatically’
C:\pstools\psexec \$servername -s -d powershell “Enable-PSRemoting -Force”

$cmd = “robocopy”
$arg = “C:\Users\clevengerl\Desktop\SCCM Project\ADK \$servername\C$\Windows\Temp\ADK /MIR /XA:SH/ipg:25000 /w:0 /log:c:\robocopy_log.txt /tee”

start-process -wait $cmd $arg

$session=New-PSSEssion -Computername $servername
Enter-PSSession -ComputerName $servername
#install ADK (reboot?)
adksetup.exe /promptrestart /ceip on /quiet “c:\program files (x86)\Windows Kits\8.0” /features +
#copy DISM to root directory/system32?
#run dism to setup the import-module servermanager Dism /online /enable-feature /featurename:ServerCore-FullServer /featurename:Server-Gui-Shell /featurename:Server-Gui-Mgmt

Invoke-Command -session $session {Import-Module Servermanager}
Invoke-Command -session $session {Add-Windowsfeature Web-Mgmt-Compat | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Metabase | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Filter | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Ext | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-WMI | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Windows-Auth | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature BITS | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature RDC | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Exit-PSSession}

}

First off I’d look at concatenating the calls to Add-WindowsFeature - you can install multiple features in one pass

I think this line is causing your main problem
} $OS = (Get-WmiObject -computername $server -class Win32_OperatingSystem -Property Version,osarchitecture ).caption

first off not sure what the } at the beginning of the line will do for you - I think you need to remove it

the line should become
$OS = (Get-WmiObject -computername $server -class Win32_OperatingSystem -Property Version,osarchitecture ).osarchitecture

$erroractionpreference = “SilentlyContinue” $servers = Get-Content -path c:\SCCMMangerScript\CSV\SCCMServers.csv foreach ($server in $servers){ $OS = (Get-WmiObject -computername $server -class Win32_OperatingSystem -Property Version,osarchitecture ).osarchitecture if ($os = “64-bit”) {

$session = New-PSSEssion -Computername $server
#Enter-PSSession -ComputerName $server
Invoke-Command -session $session {Import-Module Servermanager}
Invoke-Command -session $session {Add-Windowsfeature Web-Mgmt-Compat | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Metabase | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Filter | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Ext | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-WMI | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Windows-Auth | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature BITS | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature RDC | out-file C:\sccm_Addfeature.log -append}
#Invoke-Command -session $session {Exit-PSSession}
$session | Remove-PSSession

} #end if

elseif ($os = “32-Bit”) {

#Server 2008 32Bit (this is the one I have been having trouble with as you can see a lot has to happen for it to become a DP correctly.)

#Set-ExecutionPolicy Unrestricted
#list of 32bit servers
$servername = “nfilaub01”
C:\pstools\psexec \$servername -s -d powershell “Enable-PSRemoting -Force”

$cmd = “robocopy”
$arg = “C:\Users\clevengerl\Desktop\SCCM Project\ADK \$servername\C$\Windows\Temp\ADK /MIR /XA:SH/ipg:25000 /w:0 /log:c:\robocopy_log.txt /tee”

start-process -wait $cmd $arg

$session=New-PSSEssion -Computername $servername
#Enter-PSSession -ComputerName $servername
#install ADK (reboot?)
adksetup.exe /promptrestart /ceip on /quiet “c:\program files (x86)\Windows Kits\8.0″ /features +
#copy DISM to root directory/system32?
#run dism to setup the import-module servermanager Dism /online /enable-feature /featurename:ServerCore-FullServer /featurename:Server-Gui-Shell /featurename:Server-Gui-Mgmt

Invoke-Command -session $session {Import-Module Servermanager}
Invoke-Command -session $session {Add-Windowsfeature Web-Mgmt-Compat | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Metabase | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Filter | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Ext | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-WMI | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Windows-Auth | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature BITS | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature RDC | out-file C:\sccm_Addfeature.log -append}
#Invoke-Command -session $session {Exit-PSSession}
$session | Remove-PSSession

}

I’ve made a few changes to get you going however this line

adksetup.exe /promptrestart /ceip on /quiet “c:\program files (x86)\Windows Kits\8.0″ /features +

doesn’t appear to be complete - its missing at least a terminating "

Please try the changes and let us know how you get on

I’ll post on concatenating the Add-WindowsFeatures later

There are quite a few problems with this script:

  • There's a closing curly brace at the beginning of the next line after your foreach loop starts. It's a syntax error as written, but even if it weren't, you'd have a blank foreach loop followed by a bunch of code that executes one time. That closing curly brace is probably a typo.
  • The line to set the $OS variable is a bit off; you're pulling back the Version and OSArchitecture properties of Win32_OperatingSystem, but then assigning "Caption" to $OS (which will always be null, since you didn't retrieve the Caption property.)
  • You're calling Enter-PSSession, which has no place in a script. That is intended for console use, and puts you at an interactive PowerShell prompt on the remote computer. For scripts, stick with New-PSSession, Invoke-Command, and eventually Remove-PSSession (which you're currently not calling, but you should, when you're done with it.)
  • While not strictly a problem, you could put all of those remote commands into a single script block and send it in one call to Invoke-Command. It may run faster that way (and if only one call to Invoke-Command were needed, you wouldn't even need to worry about New-PSSession / Remove-PSSession.)
  • You're hard-coding a $serverName variable for some reason; shouldn't you be calling PSExec and Robocopy against $server in your foreach loop?
  • Your comments mention a possible reboot after installing the ADK, and before running all of the Add-WindowsFeature commands. That makes things a bit more complicated.

On a side note, if you’ve upgraded your systems to PowerShell 4.0, this might be a good opportunity to make use of Desired State Configuration. There are lots of blog posts about how to set it up, both on PowerShell.org and on the PowerShell team blog (PowerShell Team - Automating the world one-liner at a time…), and more information in the about_DesiredStateConfiguration help file.

Thanks so much for the help and yes will do, that entry } must have been there due to the foreach line above guess I either missed it or was confused. I was having some problems with running the installs in the same line but no big deal if I can at least get them running for which ever arch the server is on. Thanks again, will report back shortly.

if the add-windowsfeature finds the feature already present would it just fail without leaving a log?

•There’s a closing curly brace at the beginning of the next line after your foreach loop starts. It’s a syntax error as written, but even if it weren’t, you’d have a blank foreach loop followed by a bunch of code that executes one time. That closing curly brace is probably a typo.

Correct that was a typo

•The line to set the $OS variable is a bit off; you’re pulling back the Version and OSArchitecture properties of Win32_OperatingSystem, but then assigning “Caption” to $OS (which will always be null, since you didn’t retrieve the Caption property.)

Corrected to $OS = (Get-WmiObject -computername $server -class Win32_OperatingSystem -Property Version,osarchitecture ).osarchitecture

•You’re calling Enter-PSSession, which has no place in a script. That is intended for console use, and puts you at an interactive PowerShell prompt on the remote computer. For scripts, stick with New-PSSession, Invoke-Command, and eventually Remove-PSSession (which you’re currently not calling, but you should, when you’re done with it.)

Removed enter-pssession though i thought i needed that if ps was not already turned on for the 32bit servers but perhaps im handling that with enable-psremoting

•While not strictly a problem, you could put all of those remote commands into a single script block and send it in one call to Invoke-Command. It may run faster that way (and if only one call to Invoke-Command were needed, you wouldn’t even need to worry about New-PSSession / Remove-PSSession.)

Would perfer to leave as is till I get all the other problems sorted :stuck_out_tongue:

•You’re hard-coding a $serverName variable for some reason; shouldn’t you be calling PSExec and Robocopy against $server in your foreach loop?

Corrected.

•Your comments mention a possible reboot after installing the ADK, and before running all of the Add-WindowsFeature commands. That makes things a bit more complicated.

Yes I know, thats the problem I am having with the 32bit 2008 servers, know of a way i can leave those and force the installation without a reboot?

I think this is better but still having some trouble with how to copy and invoke the dism and adk part of the script for 32bit machines? And thanks everyone for the help, learning ps for the first time and I’m having trouble wrapping my head around all the commands and options.

Set-ExecutionPolicy Unrestricted
$erroractionpreference = “SilentlyContinue”
$servers = Get-Content -path c:\SCCMMangerScript\CSV\SCCMServers.csv
foreach ($server in $servers){
$OS = (Get-WmiObject -computername $server -class Win32_OperatingSystem -Property Version,osarchitecture ).osarchitecture
if ($os = “64-bit”) {
$session = New-PSSEssion -Computername $server
#Enter-PSSession -ComputerName $server
Invoke-Command -session $session {Import-Module Servermanager}
Invoke-Command -session $session {Add-Windowsfeature Web-Mgmt-Compat | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Metabase | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Filter | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Ext | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-WMI | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Windows-Auth | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature BITS | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature RDC | out-file C:\sccm_Addfeature.log -append}
#Invoke-Command -session $session {Exit-PSSession}
$session | Remove-PSSession}
}

elseif ($os = “32-Bit”) {
C:\pstools\psexec \$server -s -d powershell “Enable-PSRemoting -Force”
$cmd = “robocopy”
$arg = “C:\Users\clevengerl\Desktop\SCCM Project\ADK \$server\C$\Windows\Temp\ADK /MIR /XA:SH/ipg:25000 /w:0 /log:c:\robocopy_log.txt /tee”
start-process -wait $cmd $arg
$session=New-PSSEssion -Computername $server
Enter-PSSession -ComputerName $server
adksetup.exe /promptrestart /ceip on /quiet “c:\program files (x86)\Windows Kits\8.0″ /features +"
#copy DISM to root directory/system32?

#run dism to setup the import-module servermanager
Dism /online /enable-feature /featurename:ServerCore-FullServer /featurename:Server-Gui-Shell /featurename:Server-Gui-Mgmt
Invoke-Command -session $session {Import-Module Servermanager}
Invoke-Command -session $session {Add-Windowsfeature Web-Mgmt-Compat | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Metabase | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Filter | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Ext | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-WMI | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Windows-Auth | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature BITS | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature RDC | out-file C:\sccm_Addfeature.log -append}
#Invoke-Command -session $session {Exit-PSSession}
$session | Remove-PSSession}

Another change, seem to have the directory set for robocopy now only it doesnt seem to follow through to the second part of the script when the $os is reported?

Set-ExecutionPolicy Unrestricted
$erroractionpreference = “SilentlyContinue”
$servers = Get-Content -path c:\SCCMMangerScript\CSV\SCCMServers.csv
foreach ($server in $servers){
$OS = (Get-WmiObject -computername $server -class Win32_OperatingSystem -Property Version,osarchitecture ).osarchitecture
if ($os = “64-bit”) {
$session = New-PSSEssion -Computername $server
#Enter-PSSession -ComputerName $server
Invoke-Command -session $session {Import-Module Servermanager}
Invoke-Command -session $session {Add-Windowsfeature Web-Mgmt-Compat | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Metabase | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Filter | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Ext | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-WMI | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Windows-Auth | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature BITS | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature RDC | out-file C:\sccm_Addfeature.log -append}
#Invoke-Command -session $session {Exit-PSSession}
$session | Remove-PSSession}
}

elseif ($os = “32-bit”) {
C:\pstools\psexec \$server -s -d powershell “Enable-PSRemoting -Force”
$arSourceFolders = (“C:\SCCMMangerScript\ADK”)
$arDestinationFolders = (“\$server\C$\Windows\Temp\ADK”)
$cmd = robocopy $arSourceFolders $arDestinationFolders /MIR /XA:SH /ipg:25000 /w:0 /log:c:\robocopy_log.txt
start-process -wait $cmd
$session=New-PSSEssion -Computername $server
Enter-PSSession -ComputerName $server
adksetup.exe /norestart /q /ceip off /features OptionId.WindowsPreinstallationEnvironment OptionId.DeploymentTools OptionId.UserStateMigrationTool

#copy DISM to root directory/system32?

#run dism to setup the import-module servermanager
Dism /online /enable-feature /featurename:ServerCore-FullServer /featurename:Server-Gui-Shell /featurename:Server-Gui-Mgmt
Invoke-Command -session $session {Import-Module Servermanager}
Invoke-Command -session $session {Add-Windowsfeature Web-Mgmt-Compat | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Metabase | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Filter | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Ext | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-WMI | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Windows-Auth | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature BITS | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature RDC | out-file C:\sccm_Addfeature.log -append}
#Invoke-Command -session $session {Exit-PSSession}
$session | Remove-PSSession
}

I have not gotten as far as the install command $adk but it seems to be failing as it starts the adksetup.exe but then exits almost instantly, I thought the -wait would keep that from happening until it completed? Any help is appeciated.

And for refrence it is this line of code about half way down that I am stuck on…


$adk = Invoke-Command -session $session {C:\Windows\Temp\ADK\adksetup.exe /norestart /q /ceip off /features +}
Write-Host “ADK Install”
start-process -wait $adk


Set-ExecutionPolicy Unrestricted
$erroractionpreference = “SilentlyContinue”
$servers = Get-Content -path c:\SCCMMangerScript\CSV\SCCMServers.csv
foreach ($server in $servers){
$server
$os = (Get-WmiObject -computername $server -class Win32_OperatingSystem ).osarchitecture
$os | get-member
If ($os -eq “64-bit”) {
Write-host “running 64”
$session = New-PSSEssion -Computername $server
#Enter-PSSession -ComputerName $server
Invoke-Command -session $session {Import-Module Servermanager}
Invoke-Command -session $session {Add-Windowsfeature Web-Mgmt-Compat | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Metabase | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Filter | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Ext | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-WMI | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Windows-Auth | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature BITS | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature RDC | out-file C:\sccm_Addfeature.log -append}
#Invoke-Command -session $session {Exit-PSSession}
$session | Remove-PSSession }

elseif ($os -eq “32-bit”) {
Write-Host “running 32”
$arSourceFolders = (“C:\SCCMMangerScript\ADK”)
$arDestinationFolders = (“\$server\C$\Windows\Temp\ADK”)
$cmd = robocopy $arSourceFolders $arDestinationFolders /MIR /XA:SH /ipg:25000 /w:0 /log:c:\robocopy_"$server"log.txt
start-process -wait $cmd
Write-Host “Copy ADK complete”
$session = New-PSSEssion -Computername $server
$adk = Invoke-Command -session $session {C:\Windows\Temp\ADK\adksetup.exe /norestart /q /ceip off /features +}
Write-Host “ADK Install”
start-process -wait $adk
Write-Host “Complete”
#copy DISM to root directory/system32?
Invoke-command -session $session {Dism /online /enable-feature /featurename:ServerCore-FullServer /featurename:Server-Gui-Shell /featurename:Server-Gui-Mgmt}
Invoke-Command -session $session {Import-Module Servermanager}
Invoke-Command -session $session {Add-Windowsfeature Web-Mgmt-Compat | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Metabase | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Filter | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Ext | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-WMI | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Windows-Auth | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature BITS | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature RDC | out-file C:\sccm_Addfeature.log -append}
#Invoke-Command -session $session {Exit-PSSession}
$session | Remove-PSSession
}
}

This is resolved with the following turns out Add-Windows features will not work on the older 32bit version of 2008 server so i had to use Servermanagercmd line. Incase someone else has the same issue figured I would follow up.

Set-ExecutionPolicy Unrestricted
$erroractionpreference = “SilentlyContinue”
$servers = Get-Content -path c:\SCCMMangerScript\CSV\SCCMServers.csv
foreach ($server in $servers){
$server
$os = (Get-WmiObject -computername $server -class Win32_OperatingSystem ).osarchitecture
$os | get-member
If ($os -eq “64-bit”) {
Write-host “running 64”
$session = New-PSSEssion -Computername $server

Invoke-Command -session $session {Import-Module Servermanager}
Invoke-Command -session $session {Add-Windowsfeature Web-Mgmt-Compat | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Metabase | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Filter | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-ISAPI-Ext | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-WMI | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature Web-Windows-Auth | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature BITS | out-file C:\sccm_Addfeature.log -append}
Invoke-Command -session $session {Add-Windowsfeature RDC | out-file C:\sccm_Addfeature.log -append}
#Invoke-Command -session $session {Exit-PSSession}
$session | Remove-PSSession }

elseif ($os -eq “32-bit”) {
Write-Host “running 32”
$session = New-PSSession -Computername $server
Invoke-Command -session $session {ServerManagercmd -install Web-Mgmt-Compat -logpath C:\sccm_Addfeature.log}
Invoke-Command -session $session {ServerManagercmd -install Web-Metabase -logpath C:\sccm_Addfeature.log}
Invoke-Command -session $session {ServerManagercmd -install Web-ISAPI-Filter -logpath C:\sccm_Addfeature.log}
Invoke-Command -session $session {ServerManagercmd -install Web-ISAPI-Ext -logpath C:\sccm_Addfeature.log}
Invoke-Command -session $session {ServerManagercmd -install Web-WMI -logpath C:\sccm_Addfeature.log}
Invoke-Command -session $session {ServerManagercmd -install Web-Windows-Auth -logpath C:\sccm_Addfeature.log}
Invoke-Command -session $session {ServerManagercmd -install BITS -logpath C:\sccm_Addfeature.log}
Invoke-Command -session $session {ServerManagercmd -install RDC -logpath C:\sccm_Addfeature.log}
#Invoke-Command -session $session {Exit-PSSession}
$session | Remove-PSSession
}
}