Collecting roles and features on remote Windows computers

Almost all roles and features in Windows can be managed using PowerShell. However, when it comes to managing roles and features itself on remote Windows computers, Microsoft provides the necessary PowerShell cmdlets. This article explains how you can use PowerShell cmdlets to collect roles and features on local and remote Windows computers and also provides a simple PowerShell script to generate a report on installed roles and features on remote Windows computers.

PowerShell cmdlets associated with roles and features

There are three PowerShell cmdlets are associated with Windows roles and features: Get-WindowsFeature, Install-WindowsFeature, and UnInstall-WindowsFeature. As the name suggests, Get-WindowsFeature is used to get the list of roles and features installed on the Windows computers. Install-WindowsFeature is to install and UnInstall-WindowsFeature is used to uninstall roles and/or features from Windows computers.

Tip: It is important to note that all of the roles and features PowerShell cmdlets have the word “Feature” added rather than having both “role” and “feature” words. There are no cmdlets that are designed specifically to manage roles and cmdlets to manage features alone. You will be required to use the above cmdlets to manage both roles and features.

Using Get-WindowsFeature to collect roles and features

roles and features
As the name suggests, Get-WindowsFeature PowerShell cmdlet is used to collect information about the roles and features on Windows computers. You can use it to collect information from local as well as remote Windows computers. To collect features and roles from the local computer, just execute Get-WindowsFeature. The command will return a list of installed and available roles and features. In case you need to collect roles and features information from a remote Windows computer, just execute this PowerShell command:

Get-WindowsFeature –ComputerName PRODSERVER1

And to export the output to a CSV file of your choice, simply adding Export-CSV at the end of the command will work as shown in the cmdlet below:

Get-WindowsFeature –ComputerName PRODSERVER1 | Export-CSV C:\Temp\RoleAndFeatures.CSV

Note that the above PowerShell commands get both available and installed roles and features on a computer. If you just need to collect a list of installed features and roles, execute this PowerShell command:

Get-WindowsFeature -ComputerName PRODSERVER1 | Where-Object {$_.Installed -match $True} | Select-Object Property Name

And to collect a list of only available features and roles, just execute this command:

Get-WindowsFeature -ComputerName PRODSERVER1 | Where-Object {$_.Installed -match $False} | Select-Object Property Name

Let’s assume you need to prepare a report containing roles and features installed on each Windows computer in your production environment to ensure the production Windows servers do not have any roles/features that are not required. Note that a role or feature consumes system resources if a role/feature is not intended to be running on a production server, which in turn might impact the overall performance of Windows servers. To just collect installed roles and features from remote Windows computers, use this PowerShell script:

$ServersFile = "C:\Temp\ProdServers.TXT"
$ResultFile = "C:\Temp\RFReport.CSV"
$STR = "Server Name, Role/Feature Installed"
Add-Content $STR $ResultFile
ForEach ($ThisServer in GC $ServersFile)
{
$AllRF = Get-WindowsFeature -ComputerName $ThisServer | Where-Object {$_.Installed -match $True} | Select-Object Property Name
ForEach ($ThisItem in $AllRF)
{
$InstalledItem = $ThisItem.Name
$STR = $ThisServer+","+$InstalledItem
Add-Content $ResultFile $STR
}
}

Once the above PowerShell script is executed, a report will be generated under C:\Temp\RFReport.CSV. The report contains the name of the server in one column and then role and feature installed on that computer. Note the command that we have used in the above PowerShell script. If you just execute Get-WindowsFeature, it shows a list of available and installed roles and features, but since we need only roles/features that are installed, we have added “Where-Object {$_.Installed -match $True}” as you can see in the above script.

Get-WindowsFeature to collect roles and features from VHDX files

Since most organizations are running on virtualization, you might want to collect a list of roles and features installed on virtual machines. While you can use the PowerShell script above to connect to remote Windows computers regardless of the type of the machine, the PowerShell commands and script below can only be used for offline virtual machines. In other words, you cannot query roles and features in a VHD file if the VHD file is in use.

To get a list of roles and features available and installed in a VHD file, simply execute this PowerShell command:

Get-WindowsFeature –VHD E:\Temp\VM1\VHD2.VHDX

In case you need to query multiple VHD files to see the roles and features installed, you need to create a VHD file that contains the path for each VHD file. Then executing the above PowerShell command against each VHD file in ForEach loop will provide you with the required information. Here is the PowerShell script that you can try:

$VHDFile = "C:\Temp\VHDFile.CSV"
ForEach ($ThisVHD in GC $VHDFile)
{
Get-WindowsFeature -VHD $ThisVHD | Where-Object {$_.Installed -match $True} | Select-Object Property Name
}

The PowerShell script above just returns the list of installed roles and features from VHD files in the current PowerShell window.

Now you have some general information about the PowerShell cmdlets available to manage Windows roles and features. We also provided a simple PowerShell script that can be used to collect roles and features on remote Windows computers specified in a text file. And we also discussed how to query roles and features from VHDX files.

Featured image: Pixabay

About The Author

1 thought on “Collecting roles and features on remote Windows computers”

  1. Report containing roles and features installed has an error in it.

    The line
    Add-Content $STR $ResultFile

    should read
    Add-Content $ResultFile $STR

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top