Use PowerShell to Remove the GUI on Windows Server 2012

Doctor Scripto

Summary: A reader needs MCSE help with Microsoft exam 70-410 and wants to know how to use Windows PowerShell to add GUI elements from Windows Server 2012.

Hey, Scripting Guy! Question Hey, Scripting Guy! I have heard that it is possible to remove the graphical user interface (GUI) in Windows Server 2012 after you install the operating system. I have looked around the Internet but not found anything about this. I am concerned, because I am going to be doing my MCSE, and I am studying for my first test, the 70-410 exam, and that just seems like it would make a good question. So, can you help me out here?

—PH

Hey, Scripting Guy! Answer Hello PH,

Microsoft Scripting Guy, Ed Wilson, is here. This morning, I am sipping a cup of Assam Tea and eating a homemade blueberry scone that the Scripting Wife made last night. When it gets cold, Teresa enjoys cooking as a hobby, and sometimes I am fortunate, and she makes things that are my absolute favorites. Of course, she makes things that are her favorites as well, and she even makes things the neighbors enjoy—such as her famous chili—but last night it was scones. And cold it is, 22 degrees Fahrenheit (-5 degrees Celsius) with freezing rain expected this afternoon. Somehow, 22 degrees Fahrenheit seems colder in Charlotte, North Carolina, than it does, for instance, in Seattle, Washington—maybe it is all a matter of expectations.

Anyway, PH, you are in luck, because this week I took (and passed) the Installing and Configuring Windows Server 2012 (70-410) exam, so I applaud your efforts. You are also right—one of the objectives is stated as this: “convert Server Core to/from full GUI” … so, yes, it does look like removing the GUI in Windows would be a great test question.

Use the ServerManager module on Windows Server 2012

One of the great things about Windows PowerShell on Windows Server 2012 is all the great cmdlets and functions. But these did not spring into being from nothingness—indeed, Windows PowerShell 2.0 on Windows Server 2008 R2 was an extremely powerful solution. One of my favorite features on Windows Server 2008 R2 with Windows PowerShell 2.0 is the ServerManager module, which contains three cmdlets: Add-WindowsFeature, Get-WindowsFeature, and Remove-WindowsFeature.

In the following code, run from Windows PowerShell 2.0 on Windows Server 2008 R2, I imported the ServerManager module and displayed the commands from the module.

PS C:\> ipmo servermanager

PS C:\> gcm -mo servermanager

CommandType     Name                                                Definition

———–     —-                                                ———-

Cmdlet          Add-WindowsFeature                                  Add-WindowsFeature [-Name] <Feature[]> [-Include…

Cmdlet          Get-WindowsFeature                                  Get-WindowsFeature [[-Name] <String[]>] [-LogPat…

Cmdlet          Remove-WindowsFeature                               Remove-WindowsFeature [-Name] <Feature[]> [-LogP…

 

So, the ServerManager module has been around for a long time. In Windows PowerShell 3.0 on Windows Server 2012 (or on Windows 8 with the RSAT tools installed) two functions and two aliases were added to the ServerManager module. In addition, two of the cmdlets were renamed.

EXAM ALERT   In Windows Server 2012 (with Windows PowerShell 3.0) the Add-WindowsFeature cmdlet is renamed Install-WindowsFeature. The Remove-WindowsFeature cmdlet is renamed Uninstall-WindowsFeature. For backwards compatability, Add-WindowsFeature and Remove-WindowsFeature are added as aliases.

The features exposed by the ServerManager module on Windows Server 2012 are shown here.

12:57 C:\> ipmo servermanager

12:58 C:\> gcm -Module servermanager

 

CommandType     Name                                               ModuleName

———–     —-                                               ———-

Alias           Add-WindowsFeature                                 ServerManager

Alias           Remove-WindowsFeature                              ServerManager

Function        Disable-ServerManagerStandardUserRemoting          ServerManager

Function        Enable-ServerManagerStandardUserRemoting           ServerManager

Cmdlet          Get-WindowsFeature                                 ServerManager

Cmdlet          Install-WindowsFeature                             ServerManager

Cmdlet          Uninstall-WindowsFeature                           ServerManager

First find the names of the server GUI features

To find the name of the graphical elements of the Windows Server 2012 interface, use the Get-WindowsFeature (at least this one was not renamed) cmdlet. Luckily, it has both a –computername parameter as well as a –credential parameter. With the RSAT tools installed on my Windows 8 laptop, I can easily find the graphical components against a remote server. This command is shown here, where I supply administrator credentials to connect to a remote server named Hyperv2.

Get-WindowsFeature -ComputerName hyperv2 -Name *gui* -Credential iammred\administrator

The command and its associated output is shown here.

Image of command output

If I want to remove both the Server Graphical Shell and the Graphical Management Tools and Infrastructure, I can simply pipe the results of Get-WindowsFeature to Uninstall-WindowsFeature (Remove-WindowsFeature is the alias). Because I know the command requires a restart, I use the –restart parameter.

This command and its associated output is shown here.

Image of command output

If I use the –Remove switched parameter with the Uninstall-WindowsFeature cmdlet, the command uninstalls the feature and then deletes the feature from the side-by-side store (“$env:windir\WINSXS”).

Because I want the option of adding the GUI back in at some point in the future, and because I have not configured a shared WINSXS store, I do not want to remove the bits from the system disk.

Four flavors of Windows Server 2012 interface

There are actually four different flavors of the Windows Server 2012 interface. These are documented in a great TechNet Library article called Windows Server Installation Options.  The four options are shown here.

Server Core

Minimal Server Interface

Server with a GUI

Server with a GUI with Desktop Experience

Command Prompt, Windows PowerShell, .NET Framework

ADDS: MMC, Server Manager, some Control Panel apps

ADDS: Windows Explorer, Internet Explorer, Task Bar, Control Panel

ADDS: Windows Media Player, Themes, Windows 8 Shell, Windows Store

NO: MMC, Control Panel, Windows Explorer

NO: Windows Explorer, Control Panel, Task Bar

NO: Themes, Windows 8 Shell, Windows Store, Media Player

Basic parity with Windows 8 desktop

NONE

Server-Gui-Mgmt-Infra

Server-Gui-Mgmt-Infra, Server-Gui-Shell

Server-Gui-Mgmt-Infra, Server-Gui-Shell, Desktop-Experience

Windows Server 2012 core edition

Once I have a Windows Server 2012 core edition server, I can still use Remote Desktop (not much point in it), if I want to. When I do, the old-fashioned command prompt (cmd.exe) appears when logging on. Of course, I can launch Windows PowerShell by typing powershell at the command prompt. It is also possible to edit the registry to cause Windows Server 2012 core edition to automatically boot into Windows PowerShell. The image shown here illustrates Windows Server 2012 in core edition.

Image of Windows Server 2012 core edition

Here is a list of commands that takes a full installation of Windows Server 2012 to the four different GUI levels. 

Server Core Option

If the server has a full installation of Windows Server, the following command removes the two features: Server Graphical Shell and Graphical Management Tools and Infrastructure, and the resulting installation is Server Core.

Get-WindowsFeature *gui* | Uninstall-WindowsFeature –Restart

Minimal Server Interface

If the server has a full installation of Windows Server, and I need to bring the server down to minimal server interface, I only need to remove the Server-GUI-Shell. The command is shown here.

Get-WindowsFeature Server-Gui-Shell | Uninstall-WindowsFeature –Restart

Server with a GUI

If the Windows Server is installed with “Server with a GUI,” the following two features are installed (and can be verified here).

Get-WindowsFeature Server-Gui-Mgmt-Infra, Server-Gui-Shell

If the server is in Server Core mode, this command adds the two features and brings the server up to the Server with a GUI level.

Get-WindowsFeature Server-Gui-Mgmt-Infra, Server-Gui-Shell | Install-WindowsFeature –restart

Server with Desktop Experience Added (Windows 8 desktop mode)

If the server is at “Server with a GUI” mode, then the Desktop-Experience feature is not installed. This command verifies that fact.

Get-WindowsFeature Desktop-Experience

EXAM ALERT   The Desktop-Experience feature has a dash in the name. On some web sites, this makes it seem like line continuation because it actually wraps. However, DesktopExperience does NOT return anything via Get-WindowsFeature—no errors, no anything. Desktop-Experience (with a dash in the middle of the name) will let you know if the Desktop-Experience feature is installed or not.

To install the Desktop-Experience feature on your computer running Windows Server 2012 (now in truth, about the only reason for doing this is IF you are actually running Windows Server 2012 as your desktop—such as if you have installed it on your laptop—please do not do this on a production server unless there is a real-live, honest compelling business reason for doing so).

Get-WindowsFeature Desktop-Experience  | Install-WindowsFeature -Restart

PH, that is all there is to using Windows PowerShell to add and remove various features of the Windows GUI on your computer running Windows Server 2012.  Join me tomorrow when I will talk about more cool Windows PowerShell stuff.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy

0 comments

Discussion is closed.

Feedback usabilla icon