Managing Windows Server Roles & Features with PowerShell | Windows OS Hub

In Windows Server 2012R2/2016/2019, you can use the graphic Server Manager comfort to install and remove server roles and features. however, in most cases you can do the same from the PowerShell console table much faster. In this article we ’ ll consider how to manage roles and features in the modern Windows Server versions with PowerShell .

List all Installed Windows Server Roles & Feature via PowerShell

User the Get-WindowsFeature cmdlet to display the list of all available Windows Server roles and features. If you run it without parameters, you will see the information about all Windows Server components .
The name of a component ( Display Name ), its system name ( Name ) and express ( install submit : Installed, Available or Removed ) are displayed. The tilt of roles and features looks like a tree with the nest roles similar to the one you see when you install the roles in the Server Manager GUI. To install and remove any roles or features using PowerShell, you must know their system names listed in the Name column .
Get-WindowsFeature get all available roles and features on windows server via powershell
Hint. If a role or a feature is Removed, it means that its installation files are removed from the system component sote (
. If a function or a have is Removed, it means that its facility files are removed from the system part sote ( to reduce the size of WinSxS folder ) and you won ’ deoxythymidine monophosphate be able to install the role without direct Internet access or Windows Server facility ISO ( see the example with the .Net 3.5 facility ). You can remove roles or components from your prototype on-line like this :
Uninstall-WindowsFeature –Name DHCP –Remove
To install a remove DHCP function, use this cmdlet :
Install-WindowsFeature DHCP ( you will need the direct Internet access )
Or you can restore the component binary files from your Windows Server ISO visualize :
Install-WindowsFeature DHCP -Source E:\sources\sxs
You can list the install waiter features :
Get-WindowsFeature | Where-Object {$_. installstate -eq "installed"} | ft Name,Installstate
Based upon the screenshot below, this server is used as a charge server ( FileAndStorage-Services, Storage-Services roles installed ). Most of other components are used to manage or monitor the server .
Get-WindowsFeature installed
If you do not know the character list precisely, you can use wildcards. For example, to check what web components of the IIS function are installed, run this command ( the syntax is a bit abridge ) :
Get-WindowsFeature -Name web-* | Where installed
Get-WindowsFeature Name like web
You can get the tilt of install components on a remote control Windows Server :
Get-WindowsFeature -ComputerName ny-spool1 | Where installed | ft Name,Installstate
Judging by the install Print-Services and Print-Server roles, this waiter is used as a print server .
Get-WindowsFeature installed on remote Windows Server
You can use the Get-WindowsFeature cmdlet to find servers in your sphere, on which the specific function is installed. You can search your servers in a particular Active Directory OU using the Get-ADComputer cmdlet from the PowerShell ActiveDirectory module or by the provide number of servers ( $servers = ('server1', 'server2') ).

For exemplar, you want to find all file servers with the FileAndStorage-Services role in the stipulate AD organizational unit ( I am using the ocular Studio Code as a PoweShell editor ). Use the succeed handwriting :
import-module activedirectory
$Servers=get-adcomputer -properties * -Filter {Operatingsystem -notlike "*2008 R2*" -and enabled -eq "true" -and Operatingsystem -like "*Windows Server*"} -SearchBase ‘OU=Servers,OU=UK,DC=woshub,DC=com’ |select name
Foreach ($server in $Servers)
Get-WindowsFeature -name FileAndStorage-Services -ComputerName $server.Name | Where installed | ft $, Name, Installstate

In the output, you will get the list of servers, on which the specific role is installed.
find windows server in ad domain with specific role installed

How to Install Windows Server Roles & Features using PowerShell?

In order to install roles and features on Windows Server, the Install-WindowsFeature cmdlet is used .
To install the DNS server character and the management tools ( including the Powershell DNSServer faculty ) on the stream server, run this instruction :
Install-WindowsFeature DNS -IncludeManagementTools
By default, the cmdlet installs all dependent roles and features. To display the list of dependencies anterior to the initiation, use the option WhatIf :
Install-WindowsFeature -Name UpdateServices -WhatIf
For example, to install the WSUS character, you will have to install some IIS components ampere well .

What if: Continue with installation?
What if: Performing installation for "[Windows Server Update Services] Windows Server Update
What if: Performing installation for "[Windows Server Update Services] WID Database".
What if: Performing installation for "[Windows Server Update Services] WSUS Services".
What if: Performing installation for "[Web Server (IIS)] Windows Authentication".
What if: Performing installation for "[Web Server (IIS)] Dynamic Content Compression".
What if: Performing installation for "[Web Server (IIS)] Performance".
What if: Performing installation for "[Web Server (IIS)] Static Content".
What if: Performing installation for "[Windows Internal Database] Windows Internal Database".
What if: The target server may need to be restarted after the installation completes.

To install the Remote Desktop Session Host function, the RDS license function and RDS remote management tools, use the postdate command :
Install-WindowsFeature -ComputerName lon-rds3 RDS-RD-Server, RDS-Licensing –IncludeAllSubFeature –IncludeManagementTools –Restart
Install-WindowsFeature on multiple servers
If you add the –Restart argument, your server will be automatically restarted if required .
You can besides install a component with the follow command. For exercise, to install the SMTP server character :
Get-WindowsFeature -Name SMTP-Server | Install-WindowsFeature

How to Deploy Roles on Multiple Remote Windows Servers?

There is another concern choice when you deploy distinctive servers. You can install the features you want on a character Windows Server and export the list of the install roles to a CSV file :
Get-WindowsFeature | where{$_.Installed -eq $True} | select name | Export-Csv C:\PS\InstalledRoles.csv -NoTypeInformation –Verbose
Exporting all Windows Features installed to csv file
then you will be able to use this CSV file to install the like set of roles on other typical servers :
Import-Csv C:\PS\Roles.csv | foreach{ Install-WindowsFeature $ }
import csv file with roles and features on windows server
If a function or a feature is already installed, the command will return NoChangeNeeded and continue with the installation of the following function .
Or to install the lapp function set on multiple outback servers, you can use this command :
$servers = ('ny-rds1', 'ny-rds2',’ny-rds3’,’ny-rds4’)
foreach ($server in $servers) {Install-WindowsFeature RDS-RD-Server -ComputerName $server}

How to Uninstall a Role or Feature on Windows Server with PowerShell?

To remove Windows Server roles or feture, the Remove-WindowsFeature cmdlet is used .
For example, to remove a print server function, run the command :

Remove-WindowsFeature Print-Server -Restart

source :
Category : Tech

About admin

I am the owner of the website, my purpose is to bring all the most useful information to users.

Check Also


Manage participants in a zoom meeting webinar

Call the people who attend the meet as follows Alternate host host Who scheduled the …

Leave a Reply

Your email address will not be published.