Posey's Tips & Tricks

Using PowerShell To View Windows Server Roles and Features

Here are some PowerShell tricks for finding out which roles and features are installed on Windows Server.

A big part of configuring Windows Server is installing the roles and features that are required for whatever task the server is going to be performing.

Although it is easy enough to accomplish this using Server Manager, you can also manage server roles using PowerShell. In this column, I wanted to pass along some of the tricks that I use for checking out which roles and features are installed.

Before I get started, it is important to understand that the PowerShell cmdlets related to role management are part of a module called ServerManager. The ServerManager module is not loaded by default. Depending on the version of Windows Server that you are using, it may be necessary to manually load the module before using the techniques that I am about to show you.

In some of the newer versions of Windows, however, modules are automatically loaded whenever they are required. Therefore, if the techniques that I am about to show you do not work correctly, then enter the Get-Module cmdlet and see if ServerManager is listed within the list of modules. If you don't see the ServerManager module listed, you can load it by using these commands:

$M = Get-Module -ListAvailable ServerManager
Import-Module -ModuleInfo $M

With that said, you can get a nice overview of the roles and features that are installed on a machine by simply entering the Get-WindowsFeature command. You can see what the output looks like in Figure 1.

[Click on image for larger view.] Figure 1: These are the roles and features that are installed on this machine.

The list shown in the figure above is nice, but there are so many roles and features listed that the output can be a bit overwhelming. Fortunately, there are some ways to narrow things down a bit. Let's suppose that we wanted to find out whether the Hyper-V role was installed on this server. I could go through the output shown above looking for references to Hyper-V, or I could just enter this command:

Get-WindowsFeature Hyper*

You can see what the output looks like in Figure 2. Incidentally, this works for other roles besides just Hyper-V. If I wanted to see the Web components that are installed, for example, I might replace Hyper* with Web*.

[Click on image for larger view.] Figure 2: These are the Hyper-V components that are installed on this server.

So what if I wanted to find out what else is installed on the server? Well, if you look at the figure above, you will notice that three columns of information are provided: Display Name, Name and Install State. We can filter the Get-WindowsFeature command's output based on the install state of each component. If, for example, I wanted to see just the components that are installed, I could use this command:

Get-WindowsFeature | Where-Object {$_.InstallState -eq 'Installed'}

You can see in Figure 3 that this command's output is far more digestible than the output that I showed you back in Figure 1.

[Click on image for larger view.] Figure 3: I have filtered the output to show only what is installed.

All of the commands that I have shown you so far have been run against the local server, and it should come as no surprise that you can use the same basic technique to manage a remote server. What might be a bit more surprising, however, is that you can use a variation of this technique to see the roles and features that are installed on an offline Hyper-V virtual machine (VM).

As you saw in Figure 2, the machine that I have been using for my screen captures is a Hyper-V host. As you can see in Figure 4 below, the Hyper-V VMs are all offline right now. You can also see in the figure that I have a VM named DC that acts as a domain controller. So let's check DC to see if the Active Directory roles are actually installed on it. Remember, the VM is offline.

[Click on image for larger view.] Figure 4: The VMs are offline.

The Get-WindowsFeature cmdlet supports the use of a -VHD parameter that allows you to specify a virtual hard disk file. Despite the parameter's name, the virtual hard disk file can be in either .VHD or .VHDX format. You just need to append the full path and filename of the virtual hard disk file that you wish to examine. Here is an example:

Get-WindowsFeature -Vhd 'F:\VMs\DC\Virtual Hard Disks\DC.vhdx' | Where-Object{$_.InstallState -eq 'Installed'}

As you can see in Figure 5, PowerShell was able to retrieve the roles and features from my offline virtualized domain controller.

[Click on image for larger view.] Figure 5: PowerShell can display role and feature information from an offline VM.

About the Author

Brien Posey is a 22-time Microsoft MVP with decades of IT experience. As a freelance writer, Posey has written thousands of articles and contributed to several dozen books on a wide variety of IT topics. Prior to going freelance, Posey was a CIO for a national chain of hospitals and health care facilities. He has also served as a network administrator for some of the country's largest insurance companies and for the Department of Defense at Fort Knox. In addition to his continued work in IT, Posey has spent the last several years actively training as a commercial scientist-astronaut candidate in preparation to fly on a mission to study polar mesospheric clouds from space. You can follow his spaceflight training on his Web site.

Featured

comments powered by Disqus

Subscribe on YouTube

Upcoming Training Events

0 AM
Live! 360 Orlando
November 17-22, 2024
TechMentor @ Microsoft HQ
August 11-15, 2025