How to remove Roles and Features using PowerShell
In this lesson, we will learn how to remove Roles and Features from a Windows Server using PowerShell Uninstall-WindowsFeature cmdlet. In this example, we are going to remove the "DHCP Server" Role and "Remote Server Administration Tools" Feature from a Windows Server 2025 computer using PowerShell Uninstall-WindowsFeature cmdlet.
If you are new to Roles and Features in Windows Server, please click the following links to learn What are Roles and Features in Windows Server, Roles in Windows Server and Features in Windows Server.
Click the following links to learn how to add Roles and Features in Windows Server using Server Manager, how to Remove Roles and Features in Windows Server using Server Manager and how to add Roles and Features using PowerShell.
Please watch below steps to learn how to remove Roles and Features from a Windows Server using PowerShell Uninstall-WindowsFeature cmdlet. In this example, are going to remove "DHCP Server" Role and "Remote Server Administration Tools > Role Administration Tools > DHCP Server Tools" Feature using Uninstall-WindowsFeature PowerShell cmdlet.
Please note that you need to run PowerShell as Administrator to successfully remove a Role and/or a Feature to a Windows Server. Please visit following lesson to learn how to run PowerShell as administrator in Server Core.
Step 01 – Let us find whether DHCP Server Role is available and installed in this Windows Server computer (OMNISECU–12) by using Get-WindowsFeature PowerShell cmdlet. Please note that the Where-Object PowerShell cmdlet is used to select the Role or Feature has its name containing "DHCP".
PS C:\jajish> Get-WindowsFeature | Where-Object {$_.name -match "DHCP" } Display Name Name Install State ------------ ---- ------------- [X] DHCP Server DHCP Installed [X] DHCP Server Tools RSAT-DHCP Installed
Screenshot of the above Get-WindowsFeature PowerShell cmdlet output is copied below.
We can understand from the above output of the Get-WindowsFeature cmdlet, that both "DHCP Server" Role and "DHCP Server Tools" Feature are available and installed on this Windows Server computer.
If the "Install State" shows "Available", then the Role or Feature is available, not installed.
If the "Install State" shows "Installed", then the Role or Feature is available and installed.
Step 2 – Now, to remove the "DHCP Server" Role and "DHCP Server Tools" Feature on Windows Server computer OMNISECU–12, please run Uninstall-WindowsFeature PowerShell cmdlet as shown below.
PS C:\jajish> Uninstall-WindowsFeature -Name DHCP,RSAT-DHCP -ComputerName OMNISECU-12 Success Restart Needed Exit Code Feature Result ------- -------------- --------- -------------- True Yes SuccessRest... {DHCP Server, DHCP Server Tools} WARNING: You must restart this server to finish the removal process.
Please visit the following links to know the Names of the Roles in Windows Server and the Names of the Features in Windows Server.
Screenshot of the above Uninstall-WindowsFeature PowerShell cmdlet output is copied below.
You may add –Restart to above PowerShell cmdlet, if you want to restart the Windows Server automatically after the Role or Feature removal, as shown below.
PS C:\jajish> Uninstall-WindowsFeature -Name DHCP,RSAT-DHCP -ComputerName OMNISECU-12 -Restart
Step 03 – Now, run Get-WindowsFeature PowerShell cmdlet again to verify whether "DHCP Server" Role and "DHCP Server Tools" Feature are removed from the Windows Server. Make sure the output of the Get-WindowsFeature PowerShell cmdlet shows the "Install State" as "Available" for the Role and Feature.
PS C:\jajish> Get-WindowsFeature | Where-Object {$_.name -match "DHCP" } Display Name Name Install State ------------ ---- ------------- [ ] DHCP Server DHCP Available [ ] DHCP Server Tools RSAT-DHCP Available
Screenshot of the above Get-WindowsFeature PowerShell cmdlet output is copied below.
The selected Role and Feature are now removed from the destination Windows Server.
Written by Jajish Thomas.
Last updated on 11th July, 2024.