Add-WindowsFeature in Windows Server 2012

PowerShell v3 Add-WindowsFeature CmdletAdd-WindowsFeature PowerShell 3.0

This cmdlet highlights how PowerShell can perform tasks more commonly associated with the Windows Server Manager GUI.  Note that as with all PowerShell nouns, WindowsFeature is singular.


Introduction to PowerShell’s WindowsFeature

You will probably find uses for several members of this family, therefore, let us list the verbs that we can apply to the noun WindowsFeature.

# Research Cmdlets and Aliases
Get-command -Noun WindowsFeature

Resulting Cmdlets:

Alias Add-WindowsFeature 
Alias Remove-WindowsFeature 
Cmdlet Get-WindowsFeature 
Cmdlet Install-WindowsFeature 
Cmdlet Uninstall-WindowsFeature

I was shocked to find that Add-WindowsFeature is not actually a cmdlet, but an alias of Install-WindowsFeature.

Start with Get-WindowsFeature

Before we add more features, let us see what’s already installed by investigating with the ‘Get’ verb. I have also introduced a ‘Where-Object’ filter to list only those features already installed.

# List the Windows features already installed
Get-WindowsFeature | Where {$_.installed -eq $True}

Note 1: ‘Where’ is an alias of ‘Where-Object’. 

Note 2: In PowerShell 3.0 you can simplify ‘Where clauses’ thus:
Where installed -eq $True  {But I prefer the longhand version above}.

Add-WindowsFeature – Example GPMC

Remember Add-WindowsFeature is merely an alias for the Install-WindowsFeature cmdlet. One Windows feature that you may need is the Group Policy Management Console (GPMC).  Here is how we can make the GPMC available in Server 2012:

# New PowerShell 3.0 Cmdlet in Windows Server 2012
Add-WindowsFeature -Name GPMC

Note 3: PowerShell assumes that the value immediately after the command is the feature to install, thus explicitly adding -Name is optional.

Success Restart Exit Code: Feature Result
——-   ——–  ——   ——— ————–
  True     No      Success  {Group Policy Management}

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v12 v12

SolarWinds’ Network Performance Monitor will help you discover what’s happening on your network.  This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

Perhaps the NPM’s best feature is the way it suggests solutions to network problems.  Its second best feature is the ability to monitor the health of individual VMware virtual machines.  If you are interested in troubleshooting, and creating network maps, then I recommend that you give this Network Performance Monitor a try.

Download your free trial of SolarWinds Network Performance Monitor.

Get- Then Add- Multiple Windows Features

One useful technique in PowerShell is to employ the ‘Get’ verb to capture the objects then pipe the output into a ‘Set’, or in this case, an ‘Add’ cmdlet.  The benefit is that you can test the Get output before appending the action part of the command.

# Get and Add combine to install all print features.
Get-WindowsFeature –Name Print | Add-WindowsFeature

Note 4: For this technique -Name is the best way of obtaining a batch of features all containing the same word, in this case ‘Print’.  The alternative of using a clause containing Where and -like is more cumbersome and may not produce the desired outcome.

# Where (below) not as precise as -Name (above).
Get-WindowsFeature | where {$_.Name -Like "print*"}

Note 5:  The trouble with ‘Where … -Like’ is that it would miss the Internet-Print-Client feature; to be fair -match would be a better conditional operator in this example, but my point is why not stick to the power and simplicity of -Name?

Research Add-WindowsFeature Properties and Parameters

Version 3.0 of PowerShell also has the useful Show-Command which is useful for explaining parameters such as -Restart and -Source.

As with many PowerShell cmdlets you can research more properties by Appending | Get-Member.  For example, this is how I discovered FeatureType.

An Underused Technique: Combine PowerShell and GUI
If you look in the Server Manager before and after you execute PowerShell commands, then you can see the success, or troubleshoot the failure, of your scripts.

FREE White Paper: 2013 Network Management Software (NMS) Buyers GuideFree White Paper

Here is an independent evaluation of six network management solutions; compare the following must-have features:

  • Network discovery and mapping.
  • Real-time agentless monitoring.
  • Alerting and reporting.
  • Easy to use dashboard.

Evaluate network management solutions, and balance the trade-off between price and features.  Read this buyers guide for Network Management Software. Download your free copy

Get-WindowsRole and Add-WindowsRole

These two cmdlets or functions don’t actually exist, even in PowerShell v3!  However, you can mimic them by filtering for ‘Role’ using a property of Get-WindowsFeature called FeatureType.

Get-WindowsFeature | Where { $_.FeatureType -eq "Role"} `
| Format-Table FeatureType, Displayname, InstallState -Auto

See more ideas for Windows Server 2012 PowerShell scripts »

Summary of Add-WindowsFeature in Windows Server 2012

Here is a classical way of using PowerShell in Windows Server 2012.  Firstly, it’s easier to see which components are already installed, secondly, -Name makes it easier to find just the extra features you wish to install.

If you like this page then please share it with your friends


Microsoft Windows Server 2012 Topics

Windows Server 2012 Home   • Install Windows Server 2012   • Windows Server 2012 PowerShell

PowerShell Add-WindowsFeature   • Windows Server 2012 Hyper-V  • Disable IE ESC Server 2012

Shutdown Windows Server 2012   • PowerShell DHCP Scope   • Network Performance Monitor