- Interact with Azure Cosmos DB with PowerShell - Tue, Sep 14 2021
- Azure health services: Track Microsoft cloud outages and maintenance - Wed, Sep 8 2021
- Powerline: Customize your PowerShell console - Tue, Aug 31 2021
I was happy when Microsoft gave us administrators the ability in Windows Server 2012 to switch between the Server Core and Server with a GUI environments without having to reinstall the operating system. This way, we can perform our initial installation and configuration under the full graphical user interface (GUI), and then strip down to Server Core once the box is ready for production use.
In my environment, I’m running Windows Server 2012 R2 and Windows PowerShell v5. You can obtain Windows PowerShell v5 CTP by downloading and installing Windows Management Framework (WMF) v5.
Understanding the GUI layers ^
Windows Server 2012 R2 can switch among the following GUI “layers” without having to reload the OS:
- Server Core
- Minimal Server Interface
- Server with a GUI
- Desktop Experience
The Server Core option, which I show you in the following screenshot, is the default Windows Server 2012 installation mode. The key advantages of Server Core are that you have a smaller disk installation footprint, a reduced attack surface (fewer services running means there are fewer services to exploit), and increased performance because the system doesn’t have to manage the overhead of Explorer.exe.
Server Core showing the sconfig utility
Server Core was originally pretty weak, supporting only a few server roles. I’m happy to say that, in Windows Server 2012 R2 Server Core, you can do most of the things that you can do with the Server with a GUI option. You can tell you’re running in Server Core due to the blue default background color and (more obviously) the lack of the Taskbar and Desktop icons. Moreover, you’ll get an error if you type servermanager to start Server Manager.
The next level of the GUI stack is the Minimal Server Interface, also affectionately known as MinWin. I show you the interface in the following screenshot:
Minimal Server Interface, a.k.a. MinWin
The Minimal Server Interface strikes a balance between the high security and performance of Server Core and the usability of Server with a GUI. In MinWin, you can fire up Server Manager by typing servermanager at the command prompt. You also have access to a subset of Control Panel applets—but, alas, no Internet Explorer! You can tell you’re in the Minimal Server Interface because of the default black background color and, again, the lack of a Taskbar and Desktop icons.
The Server with a GUI option is the traditional installation option we’ve had in Windows Server since the earliest days of Windows NT. By including the Desktop Experience feature (which requires Server with a GUI to already be installed), you enable a number of features of the operating system, including, but not limited to, the following:
- Windows Store
- PC Settings app
- Windows Media Player
- Sync Center
- Disk Cleanup
- Character Map
Before you ask “Why would you enable Desktop Experience on a server?”, understand that the feature is often required in Virtual Desktop Infrastructure (VDI) environments. I show you the Desktop Experience Start Screen in the following screenshot:
Server with a GUI option with Desktop Experience feature added
Issue the following command to learn the names of the Windows Server 2012 GUI layers:
Get-WindowsFeature | Format-Table -AutoSize | Out-file c:\features.txt | notepad c:\features.txt
This is what the command is doing:
- Retrieves a list of all possible Windows features, regardless of whether they are installed
- Formats the output in a tabular view with auto-sized columns
- Outputs the table to a text file
- Opens the file in Windows Notepad
Windows PowerShell gives you a lot of flexibility in output formats.
If you’re going to memorize any of these feature names, it might as well be the short names for the GUI layers. Let me present the long and short names in a list for your convenience:
- Graphical Management Tools and Infrastructure > Server-Gui-Mgmt-Infra (Minimal Server Interface)
- Server Graphical Shell > Server-Gui-Shell (Server with a GUI)
- Desktop Experience > Desktop-Experience (Desktop Experience)
I crafted the following Visio drawing to summarize how these GUI layers relate to each other:
How the Windows Server 2012 GUI layers relate to each other
The major takeaways for you concerning my GUI layer diagram are as follows:
- Server with a GUI includes the Server-Gui-Shell and Server-Gui-Mgmt-Infra components, but really all you need to install to get this layer is Server-Gui-Shell.
- Minimal Server Interface includes only the Server-Gui-Mgmt-Infra component.
- To get Server Core, you uninstall both Server-Gui-Shell and Server-Gui-Mgmt-Infra.
A power user tip: You might have noticed the User-Interfaces-Infra component in the features list. You can remove this component from either MinWin or Server with a GUI to quickly reach Server Core status.
Switching among the GUI layers ^
Let’s get to the good stuff. Imagine that we performed a “spousal” installation of Windows Server 2012 by clicking Next > Next and so on. This (non-recommended) installation approach means that we find ourselves in Server Core, which can strike fear into the hearts of some Windows systems administrators.
To go from Server Core to Minimal Server Interface, use this command:
Install-WindowsFeature Server-Gui-Mgmt-Infra -Restart
Technically, the Restart parameter is optional. However, you have to reboot anyway to make this change go into effect, so you might as well automate it.
To go from Server Core directly to Server with a GUI, use this command:
Add-WindowsFeature Server-Gui-Shell -Restart
I’m not sure if you knew this, but most Windows PowerShell commands are case-insensitive. Thus, Install-WindowsFeature, install-windowsfeature, and INSTALL-WINDOWSFEATURE are synonymous.
Now, imagine that our server is running in Desktop Experience mode, and we want to increase the performance, stability, and security of our system. To go from Desktop Experience to Server with a GUI, do this:
Remove-WindowsFeature Desktop-Experience -Restart
To go from Server with a GUI to Minimal Server Interface, try the following:
Uninstall-WindowsFeature Server-Gui-Shell -Restart
Finally, to transition from Server with a GUI to Server Core, do this:
Remove-WindowsFeature User-Interfaces-Infra -Restart
I think you have the point now. We use Add/Install-WindowsFeature or Remove/Uninstall-WindowsFeature with the short name of a target GUI layer to switch among GUI layers. Pretty easy, eh? And only one system restart is required.
Introducing Features on Demand ^
I said earlier in this article that Server Core (and, to an extent, Minimal Server Interface) can increase system security because features and services that aren’t running can’t directly be compromised. However, if the binaries to install those features persist on the computer, it is feasible that a malicious user could install them as a stepping stone to abuse your server.
To address this situation, Microsoft gives us Features on Demand. Let’s say that we are running our Windows Server 2012 R2 system in Server with a GUI mode. Our goal is to transition to Server Core and to remove the underlying installation binaries as well. To accomplish this goal, issue the following command from an elevated Windows PowerShell console session:
Remove-WindowsFeature Server-Gui-Shell,Server-Gui-Mgmt-Infra -Remove -Restart
In this case, it’s the Remove optional parameter that does the magic for us. When you come back from the reboot, you’ll be running in Server Core. Now, for grins, try the following:
Add-WindowsFeature Server-Gui-Mgmt-Infra -Restart
What happened? Here, let me show you in the following screenshot:
Missing source files
If the source files aren’t on the system, you’ll see “blood on the screen” (in other words, a Windows PowerShell error message).
We’ll now need to invoke the optional Source parameter of the Add/Install-WindowsFeature cmdlets if we want to add GUI layers to our system. In our final example, we’ll go from Server Core back to Server with a GUI, specifying a DVD source path to the Windows Server 2012 R2 installation files:
Install-WindowsFeature Server-Gui-Shell -Source wim:d:\sources\install.wim:4 -Restart
Note that the Source path needs to point to an OS image contained inside a Windows Server 2012 .wim file, from either a mounted DVD or a local/remote directory. You don’t have to mount the .wim file for PowerShell to be able to get to it, but you do need to know the index number of the OS version required. To get that info, run DISM:
dism /get-wiminfo /wimfile:d:\sources\install.wim
NOTE: I have run into trouble in Windows Server 2012 R2 trying to reinstall GUI layers by specifying the Source parameter. I don’t have the space to get into it here, but here are some links to get you started if you’ve seen the problem yourself:
- Switch from Windows Server 2012 Core to GUI Mode…Hands On!
- You Can’t Install Features in Windows Server 2012 R2
- Windows Server 2012 Shell Game
That’s all there is to it! I hope that you found this article helpful.