I wrote a PowerShell script for Server 2008 R2, to check if certain roles and features are installed and if they aren’t to install them (of course I imported the ServerManager Module at first) i.e.:
if ((Get-WindowsFeature AS-NET-Framework).Installed -eq 0)
{$InstallFeatures += "AS-NET-Framework,"
Write-Host "AS-NET-Framework will be added"}
if ((Get-WindowsFeature GPMC).Installed -eq 0)
{$InstallFeatures += "GPMC,"
Write-Host "GPMC will be added"}
but when I invoke
Add-WindowsFeature $InstallFeatures
it gives an Error that the name wasn’t found.
Somehow PS doesn’t accept the comma as delimiter in a string.
But if you type
Add-WindowsFeature AS-NET-Framwork,GPMC
in the console it works just fine.
Is there any way to to invoke the Add-WindowsFeature with all the parameters I need in one line without creating a new variable for each check, because then I’d only need one reboot for all missing roles and features?
Thanks in advance.
try declaring :
before your code.
The signature for
Get-WindowsFeatureis:the parameter name accept a
string arrayand not astring.In your code you need to remove the commas as I wrote above.