
Installing roles and features using Windows PowerShell
To install server roles and features on more than one server at the same time, or to script role and feature installations in more complex scenarios, using Server Manager is not practical, nor does it provide the desired functionality, such as managing multiple servers at once. This is where Windows PowerShell excels, controlling server with either GUI or Server Core version. PowerShell is a task-based command shell and scripting language developed by Microsoft for the purpose of configuration management and task automation. It is based on the .NET Framework, is open source, and can be installed on Windows, macOS, and Linux platforms.
To install server roles and features using Windows PowerShell, you need to run a PowerShell session with elevated user rights, unless you are installing them on a remote server.
To list roles and features that are available locally on a server, type Get-WindowsFeature or Get-WindowsFeature -computerName <computer_name>, where <computer_name> represents the name of the remote computer you are connecting to. The roles are listed first, followed by the features. In PowerShell terminology, the term role is not used, only features; cmdlets do not differentiate between the two. The following screenshot shows the output of the Windows PowerShell Get-WindowsFeature command:

To install a server role or a feature type, enter the following command:
Install-WindowsFeature -Name <feature_name> -computerName <computer_name>
To install multiple roles and features, separate values using a comma. The management tools needed to manage installed roles and features will be also installed, and your computer will restart if required once the command completes. The following PowerShell command will install the DNS role and XPS Viewer onto a computer using FQDN SRV1.MCSAGUIDE.LOCAL:
Install-WindowsFeature -Name DNS,XPS-Viewer -ComputerName srv1.mcsacertguide.local -IncludeManagementTools -Restart
To verify the installation, run the Get-WindowsFeature command or open Server Manager. On the All Servers page, right-click on a server and select Add Roles and Features.
If needed, list all currently installed features using Windows PowerShell on a target server with the Get-WindowsFeature command. To uninstall or remove roles and features, type the following command:
Uninstall-WindowsFeature -Name <feature_name> -computerName <computer_name> -Restart.
The -Restart switch is not mandatory, but will initiate a computer restart if this is necessary to complete the removal process.