Windows Server 2012 R2 Installation Options and Features on Demand (Part 3 of 5)

This 5-part blog post series details the concepts, processes, and operations of Windows Server 2012 R2 installations options and the underlying technology, Features on Demand, as the following:

  1. Introduction
  2. Using DISM Command Line
  3. Using Server Manager PowerShell Cmdlets  (This article)
  4. Switching Server Installation Options
  5. Minimizing Server Footprint

A quick review of these capabilities in Windows Server 2012 is included in https://aka.ms/7ways

Server Manager PowerShell Cmdlets

For daily system administration, Features on Demand is available via Server Manager PowerShell cmdlets. To find out which PowerShell models are loaded or available, simply run:

get-module

get-module –listAvailable

as shown here:

image

If Server Manager PowerShell module is not already installed, it can be imported with

import-module ServerManager -passthru

image

Use get-commandto list out and there are three cmdlets in ServerManager module as shown below..

clip_image002

Notice that Install-WindowsFeature and Uninstall-WindowsFeature replace Add-WindowsFeature and Remove-WindowsFeature, respectively. The latter two cmdlets were used to install features in Windows Server 2008 R2 and are now as aliases.

 

Identify Current State

The first thing to do is to always use Get-WindowsFeature to find out what roles and features are available and the current state of the machine. The output also reveals the precise Feature Names to use with Server Manager PowerShell cmdlets as shown below.

image

Display Name shows what we see in Server Manager graphical UI when adding or removing roles and features. The actual class or object names are listed under Name. The object name is what to use with Server Manager cmdlets. A checkmark preceding a display name means that the role or feature is currently installed as indicated by what is shown in the Install State column as well.

Install/Uninstall Windows Roles and Features

To disable a Windows feature, use the Uninstall-WindowsFeature cmdlet. This makes a feature unavailable, however the associated payloads are still in place. Basically the feature is disabled, nevertheless the associated code is still there. This also means the feature can be easily restored by Install-WindowsFeaturewithout reinstalling the source code.

image

The following are PowerShell examples to disable and later re-enable the feature with the display name, Server Graphical Shell, and Server-Gui-Shell (which is a feature component under User Interfaces and Infrastructure) as the corresponding parameter name on the local machine. In Part 4 of this series, it will become evident that this particular component is relevant to a server installation option. 

Uninstall-WindowsFeature Server-Gui-Shell -Restart

Install-WindowsFeature Server-Gui-Shell -Restart

Again the above operations basically make Server Graphical Shell unavailable without actually removing the associated code from the local machine, or enable Server Graphical Shell based on already installed code on the local machine. Since there is no code being removed or added, the footprint of the installation is not changed.

Conceptually, the uninstalling and installing a Windows feature with PowerShell work similarly to the Remove Roles and Features Wizard in Server Manager. However contrary to the Wizard which installs management tools by default, neither Uninstall-WindowsFeature nor Install-WindowsFeature installs the management tools for roles, role services, and features unless the parameter, IncludeManagementTools, is specified. In addition, since changing a Windows feature requires elevation, both cmdlet must be running in a Windows PowerShell session as an administrator. For more information, run Get-Helpon these cmdlets with the parameter, Full, as the following:

Get-Help Uninstall-WindowsFeature –Full

Remove Payloads

To remove the payloads of a Windows feature, use the Uninstall-WindowsFeature cmdlet with the parameter, Remove, similar to the statement below. Here, payloads of the component, Server-Gui-Shell, is removed from the local installation.

Uninstall-WindowsFeature Server-Gui-Shell –Remove -Restart

This cmdlet uninstalls features and removes the payloads from a specified computer. Notice that with the parameter, Remove, it now uninstalls and deletes the features from the side-by-side store, located at %SystemDrive%:\Windows\WinSxS

Running Uninstall-WindowsFeature with the parameter, Remove, brings the feature to a state, “Disabled with payload removed.” You will see this shown in the “Install State” column of those roles and features with payloads removed from the output of Get-WindowsFeature.

Reinstall Payloads

To reinstall features with the state, “Disabled with payload removed”, an administrator runs Install-WindowsFeature cmdlet with the parameter, Source, for specifying the location of an installation source. And the source must be from the exact same version of Windows for the reinstallation to work. Without the parameter, Source, PowerShell will use Windows Update by default to look for an installation source. The following statement restores server graphical shell from a side-by-side folder is in D drive, for example.

Install-WindowsFeature Server-Gui-Shell –Source d:\source\sxs

The cmdlet restores specified roles, role services, and features on a computer that is running Windows Server 2012 and later, or on an offline virtual hard disk (VHD) on which Windows Server 2012 and later is installed. With the parameter, Source, referencing either a network path or the path to a Windows image file (WIM), Install-WindowsFeaturecan reinstall the associated payloads to the local side-by-side store.

[To Part 1, 2, 4, 5]