PowerShell – Get installed/enabled Windows Features
Sometime you need to ‘clone’ the Windows feature-set of a specific server. That’s a task I’m currently working on. Using PowerShell to enumerate/list all enabled Windows Features is easy…
First you need to Import the ServerManager Module, then list the Modules:
PS C:\> Import-Module ServerManager
PS C:\> Get-WindowsFeature | Where-Object {$_.Installed -match “True”} | Select-Object -Property Name
Name
—-
File-Services
FS-FileServer
Web-Server
Web-WebServer
Web-Common-Http
Web-Static-Content
Web-Default-Doc
Web-Dir-Browsing
Web-Http-Errors
Web-App-Dev
Web-Asp-Net
Web-Net-Ext
Web-ISAPI-Ext
Web-ISAPI-Filter
Web-Health
Web-Http-Logging
Web-Log-Libraries
Web-Request-Monitor
Web-Http-Tracing
Web-Custom-Logging
Web-Security
Web-Windows-Auth
Web-Digest-Auth
Web-Client-Auth
Web-Cert-Auth
Web-Filtering
Web-Performance
Web-Stat-Compression
Web-Mgmt-Tools
Web-Mgmt-Console
NET-Framework
NET-Framework-Core
RSAT
RSAT-Role-Tools
RSAT-Web-Server
Telnet-Client
PowerShell-ISE
PS C:\>
Next, if you want to redirect the output to a file add a pipe and out-file <file path> to the above command/call
PS C:\> Get-WindowsFeature | Where-Object {$_.Installed -match “True”} | Select-Object -Property Name | Out-File C:\Temp\WindowsFeatures.txt
To ‘clone’ another server/add exactly the same feature-set to another Server, simple add Add-WindowsFeature in front of every Feature. it should look like that:
Add-WindowsFeature File-Services
Add-WindowsFeature FS-FileServer
Add-WindowsFeature Web-Server
Add-WindowsFeature Web-WebServer
Add-WindowsFeature Web-Common-http
Add-WindowsFeature Web-Static-Content
Add-WindowsFeature Web-Default-Doc
Add-WindowsFeature Web-Dir-Browsing
Add-WindowsFeature Web-Http-Errors
Add-WindowsFeature Web-App-Dev
Add-WindowsFeature Web-Asp-Net
Add-WindowsFeature Web-Net-Ext
Add-WindowsFeature Web-ISAPI-Ext
Add-WindowsFeature Web-ISAPI-Filter
Add-WindowsFeature Web-Health
Add-WindowsFeature Web-Http-Logging
Add-WindowsFeature Web-Log-Libraries
Add-WindowsFeature Web-Request-Monitor
Add-WindowsFeature Web-Http-Tracing
Add-WindowsFeature Web-Custom-Logging
Add-WindowsFeature Web-Security
Add-WindowsFeature Web-Windows-Auth
Add-WindowsFeature Web-Digest-Auth
Add-WindowsFeature Web-Client-Auth
Add-WindowsFeature Web-Cert-Auth
Add-WindowsFeature Web-Filtering
Add-WindowsFeature Web-Performance
Add-WindowsFeature Web-Stat-Compression
Add-WindowsFeature Web-Mgmt-Tools
Add-WindowsFeature Web-Mgmt-Console
Add-WindowsFeature NET-Framework
Add-WindowsFeature NET-Framework-Core
Add-WindowsFeature RSAT
Add-WindowsFeature RSAT-Role-Tools
Add-WindowsFeature RSAT-Web-Server
Add-WindowsFeature PowerShell-ISE
When using Add-WindowsFeature, you can add multiple features in a single command by comma-seperating them.
Use the output from “Get-WindowsFeature | Where-Object {$_.Installed -match “True”} | Select-Object -Property Name” to create a single PS command to install all featurs. Add a -reboot to restart the server.
Some features need a reboot (like .Net and Backup) and some have dependancies. I find it best to run the same command again after the reboot to make sure all features are installed. The second time it will just skip everything that is already installed.
A great way to document a Windows installation is by saving the Add-WindowsFeature PS commandline as part of the documentation.
To ‘clone’ an installation, do the filtered “Get” first, then run the “Add” on the new server!
Great stuff!
George/
If you don’t want to type all of the features, here it is a neat way to fully automate the process.
Step 1: Run PowerShell with ServerManager module:
Import-module servermanager
Step 2: Export list of currently installed features to XML and copy the xml file to the remote server
Get-WindowsFeature | ? { $_.Installed } | ? { $_.SubFeatures.Count -eq 0 } | Export-Clixml C:\temp\features.xml
Copy-Item c:\temp\features.xml \\yourserver\c$\temp
Step 3: On second server, run PowerShell, Import the ServerManager module and import XML
$f = Import-Clixml C:\temp\features.xml
Step 4: Pipe that bad boy into Add-WindowsFeature!
$f | Add-WindowsFeature
Step 5: Restart, if needed
Restart-Computer
Guys this is awesome and thank you first and foremost. We have a lot of severs here that we deploy and being able to standardize the template to deploy is amazing.
One problem I ran into, which I can’t seem to solve is .NET 3.5 which requires the source files. I’ve tried adding the -Source X:\Sources\sxs to the command string, but it consistently fails. Any ideas? Error is copied below.
Add-WindowsFeature : The request to add or remove features on the specified server failed.
Installation of one or more roles, role services, or features failed.
The source files could not be downloaded.
Use the “source” option to specify the location of the files that are required to restore the feature. For more
information on specifying a source location, see http://go.microsoft.com/fwlink/?LinkId=243077. Error: 0x800f0906
At line:1 char:4
+ $f|Add-WindowsFeature -source F:\Sources\sxs
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (@{Vhd=; Credent…Name=localhost}:PSObject) [Install-WindowsFeature],
Exception
+ FullyQualifiedErrorId : DISMAPI_Error__Cbs_Download_Failure,Microsoft.Windows.ServerManager.Commands.AddWindowsF
eatureCommand