I didn't see anything specific to this with a quick Google, so I thought I'd post this. Perhaps, it will help other administrators replicate/copy Windows features and roles to multiple servers from a source server. In my particular case I needed to copy the features and roles from a test environment server to a certification server.
This will add new features and roles as well as remove any not in use from the source to the localhost.
Note: The Remove-WindowsFeature may fail if a reboot is required after the Add-WindowsFeature completes. Just run the command again after the server is rebooted.
Note: The script had to select only features that have no subfeatures to install, otherwise, the -IncludeAllSubFeature seems to trigger regardless of passing $false to it.
This will add new features and roles as well as remove any not in use from the source to the localhost.
- param([string] $Source)
- Import-Module ServerManager
- $features = Invoke-Command -Computer $Source -Script {
- Import-Module ServerManager
- Get-WindowsFeature
- }
- $features |? { $_.Installed -and $_.SubFeatures.Count -eq 0} | Add-WindowsFeature
- $features |? { !$_.Installed } | Remove-WindowsFeature
Note: The Remove-WindowsFeature may fail if a reboot is required after the Add-WindowsFeature completes. Just run the command again after the server is rebooted.
Note: The script had to select only features that have no subfeatures to install, otherwise, the -IncludeAllSubFeature seems to trigger regardless of passing $false to it.
Comments
Post a Comment