Managing Windows Server Roles & Features with PowerShell

In Windows Server 2012R2/2016/2019, you should utilize the graphical Server Manager console to put in and take away server roles and options. However, generally you are able to do the identical from the PowerShell console a lot quicker. In this text we’ll think about tips on how to handle roles and options within the trendy Windows Server variations with PowerShell.

List all Installed Windows Server Roles & Feature through PowerShell

User the Get-WindowsFeature cmdlet to show the record of all out there Windows Server roles and options. If you run it with out parameters, you will notice the details about all Windows Server elements.

The identify of a element (Display Name), its system identify (Name) and state (Install State: Installed, Available or Removed) are displayed. The record of roles and options seems like a tree with the nested roles just like the one you see whenever you set up the roles within the Server Manager GUI. To set up and take away any roles or options utilizing PowerShell, you need to know their system names listed within the Name column.

Get-WindowsFeature get all available roles and features on windows server via powershell

Hint. If a task or a function is Removed, it signifies that its set up information are faraway from the system element sote () and also you received’t be capable to set up the function with out direct Internet entry or Windows Server set up ISO (see the instance with the ).

You can take away roles or elements out of your picture on-line like this:

Uninstall-WindowsFeature –Name DHCP –Remove

To set up a eliminated function, use this cmdlet:

Install-WindowsFeature DHCP (you will want the direct Internet entry)

Or you’ll be able to restore the element binary information out of your Windows Server ISO picture:

Install-WindowsFeature DHCP -Source E:sourcessxs

You can record the put in server options:

Get-WindowsFeature | Where-Object | ft Name,Installstate

Based upon the screenshot under, this server is used as a file server (FileAndStorage-Services, Storage-Services roles put in). Most of different elements are used to handle or monitor the server.

Get-WindowsFeature installed

If you have no idea the function identify precisely, you should utilize wildcards. For instance, to examine what internet elements of the IIS function are put in, run this command (the syntax is a bit shortened):

Get-WindowsFeature -Name web-* | Where put in

Get-WindowsFeature Name like web

You can get the record of put in elements on a distant Windows Server:

Get-WindowsFeature -LaptopName ny-spool1 | Where put in | ft Name,Installstate

Judging by the put in Print-Services and Print-Server roles, this server is used as a print server.

Get-WindowsFeature installed on remote Windows Server

You can use the Get-WindowsFeature cmdlet to seek out servers in your area, on which the particular function is put in. You can search your servers in a selected Active Directory OU utilizing the cmdlet from or by the supplied record of servers ($servers = ('server1', 'server2')).

For instance, you wish to discover all file servers with the FileAndStorage-Services function within the specified AD organizational unit (I’m utilizing the ). Use the next script:

import-module activedirectory
$Servers=get-adcomputer -properties * -Filter -SearchBase ‘OU=Servers,OU=UK,DC=woshub,DC=com’ |choose identify
Foreach ($server in $Servers)
Where put in

In the output, you’re going to get the record of servers, on which the particular function is put in.
find windows server in ad domain with specific role installed

How to Install Windows Server Roles & Features utilizing PowerShell?

In order to put in roles and options on Windows Server, the Install-WindowsFeature cmdlet is used.

To set up the DNS server function and the administration instruments (together with the Powershell ) on the present server, run this command:

Install-WindowsFeature DNS -IncludeManagementTools

By default, the cmdlet installs all dependent roles and options. To show the record of dependencies previous to the set up, use the choice WhatIf:
Install-WindowsFeature -Name UpdateServices -WhatIf

For instance, to , you’ll have to set up some IIS elements as properly.

What if: Continue with set up?
What if: Performing set up for "[Windows Server Update Services] Windows Server Update
What if: Performing set up for "[Windows Server Update Services] WID Database".
What if: Performing set up for "[Windows Server Update Services] WSUS Services".
What if: Performing set up for "[Web Server (IIS)] Windows Authentication".
What if: Performing set up for "[Web Server (IIS)] Dynamic Content Compression".
What if: Performing set up for "[Web Server (IIS)] Performance".
What if: Performing set up for "[Web Server (IIS)] Static Content".
What if: Performing set up for "[Windows Internal Database] Windows Internal Database".
What if: The goal server might must be restarted after the set up completes.

To set up the Remote Desktop Session Host function, the and RDS distant administration instruments, use the next command:

Install-WindowsFeature -LaptopName lon-rds3 RDS-RD-Server, RDS-Licensing –IncludeAllSubFeature –IncludeManagementTools –Restart

Install-WindowsFeature on multiple servers

If you add the –Restart parameter, your server shall be routinely restarted if required.

You may set up a element with the next command. For instance, to :

Get-WindowsFeature -Name SMTP-Server | Install-WindowsFeature

How to Deploy Roles on Multiple Remote Windows Servers?

There is one other attention-grabbing possibility whenever you deploy typical servers. You can set up the options you need on a reference Windows Server and export the record of the put in roles to a CSV file:

Get-WindowsFeature | the place | choose identify | Export-Csv C:PSInstalledRoles.csv -NoTypeInformation –Verbose

Exporting all Windows Features installed to csv file

Then it is possible for you to to make use of this CSV file to put in the identical set of roles on different typical servers:

Import-Csv C:PSRoles.csv | foreach

import csv file with roles and features on windows server

If a task or a function is already put in, the command will return NoChangeNeeded and proceed with the set up of the subsequent function.

Or to put in the identical function set on a number of distant servers, you should utilize this command:

$servers = ('ny-rds1', 'ny-rds2',’ny-rds3’,’ny-rds4’)
foreach ($server in $servers)

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

To take away Windows Server roles or feture, the Remove-WindowsFeature cmdlet is used.

For instance, to take away a print server function, run the command:

Remove-WindowsFeature Print-Server -Restart

Check Also

How to Enable and Configure MPIO on Windows Server 2016/2012R2?

In this text we’ll contemplate how to set up and configure MPIO on Windows Server …

Leave a Reply

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