How to add Roles and Features using PowerShell
In this lesson, we will learn how to add Roles and Features in Windows Server using PowerShell. In this example, we are going to add "DHCP Server" Role and "Remote Server Administration Tools" Feature to a newly installed Windows Server 2025 computer using Install-WindowsFeature PowerShell 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 remove Roles and Features using PowerShell.
Please watch below steps to learn how to add Roles and Features in a Windows Server using PowerShell Install-WindowsFeature cmdlet. In this example, we will install "DHCP Server" Role and "Remote Server Administration Tools > Role Administration Tools > DHCP Server Tools" Feature using Install-WindowsFeature PowerShell cmdlet.
Please note that you need to run PowerShell as Administrator to successfully add 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 – First, let us find whether DHCP Server Role is available 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 ------------ ---- ------------- [ ] DHCP Server DHCP Available [ ] DHCP Server Tools RSAT-DHCP Available C:\Users\jajish>
Screenshot of the 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 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 add "DHCP Server" Role and "DHCP Server Tools" Feature on Windows Server computer OMNISECU–12, please run Install-WindowsFeature PowerShell cmdlet as shown below.
PS C:\jajish> Install-WindowsFeature -Name DHCP -ComputerName OMNISECU-12 -IncludeManagementTools -Restart Success Restart Needed Exit Code Feature Result ------- -------------- --------- -------------- True No Success {DHCP Server, DHCP Server Tools} PS C:\jajish>
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 Install-WindowsFeature PowerShell cmdlet output is copied below.
Step 3 – Now, run Get-WindowsFeature PowerShell cmdlet again to verify whether "DHCP Server" Role and "DHCP Server Tools" Feature are installed. Make sure the output of the Get-WindowsFeature PowerShell cmdlet shows the "Install State" as "Installed" for the Role and Feature.
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.
The selected Role and Feature are now added to the destination Windows Server.
Written by Jajish Thomas.
Last updated on 10th July, 2024.