Introduction
Windows Server 2012 R2 uses a role-based architecture where specific services are added as “Server Roles” (major features like IIS, AD DS, DHCP) and “Features” (supporting components like .NET Framework, RSAT). PowerShell’s Server Manager module provides complete programmatic control over role and feature installation, making it possible to automate server configuration with precise reproducibility. This guide covers adding and removing all common roles and features on Windows Server 2012 R2.
Listing Available Roles and Features
# List all available roles
Get-WindowsFeature | Where-Object {$_.FeatureType -eq 'Role'} |
Select-Object Name,DisplayName,Installed | Format-Table -AutoSize
# List all available features
Get-WindowsFeature | Where-Object {$_.FeatureType -eq 'Feature'} |
Select-Object Name,DisplayName,Installed | Format-Table -AutoSize
# Search for a specific role/feature
Get-WindowsFeature | Where-Object {$_.DisplayName -like '*Web*'}
Installing Common Roles
# Install Web Server (IIS) with management tools
Install-WindowsFeature Web-Server -IncludeManagementTools
# Install Active Directory Domain Services
Install-WindowsFeature AD-Domain-Services -IncludeManagementTools
# Install DNS Server
Install-WindowsFeature DNS -IncludeManagementTools
# Install DHCP Server
Install-WindowsFeature DHCP -IncludeManagementTools
# Install File Services (includes SMB file sharing)
Install-WindowsFeature FS-FileServer
# Install Hyper-V (requires hardware virtualisation support)
Install-WindowsFeature Hyper-V -IncludeManagementTools -Restart
# Install Remote Desktop Services (Session Host)
Install-WindowsFeature RDS-RD-Server -IncludeManagementTools
Installing Multiple Roles at Once
# Install a LAMP-equivalent stack roles in one command
Install-WindowsFeature Web-Server, Web-CGI, Web-ISAPI-Ext, Web-ISAPI-Filter, `
Web-Basic-Auth, Web-Windows-Auth, Web-Mgmt-Console, `
NET-Framework-45-Core, NET-Framework-45-ASPNET `
-IncludeManagementTools
# Install full .NET Framework stack
Install-WindowsFeature NET-Framework-45-Features, NET-Framework-Core,
NET-Framework-45-Core, NET-WCF-Services45
# Check installation result
$result = Install-WindowsFeature Web-Server -IncludeManagementTools
if ($result.Success) {
Write-Host "Installation successful. Restart needed: $($result.RestartNeeded)"
}
Installing Features from a Specific Source
# Some features require installation source (for Server Core or stripped installs)
# Mount the Windows Server 2012 R2 ISO and use sourcessxs as source
Install-WindowsFeature NET-Framework-Core -Source D:sourcessxs
# Or specify a network share
Install-WindowsFeature NET-Framework-Core -Source \fileserversharews2012r2sourcessxs
# For DISM-based installs (alternative approach)
DISM /Online /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:D:sourcessxs
Removing Roles and Features
# Remove IIS
Uninstall-WindowsFeature Web-Server -IncludeManagementTools
# Remove a role but keep management tools
Uninstall-WindowsFeature DHCP -Remove
# Remove multiple features at once
Uninstall-WindowsFeature RDS-RD-Server, RDS-Licensing
# Remove unused features to reduce attack surface (Server Core recommendation)
$unusedFeatures = @(
'Telnet-Client',
'TFTP-Client',
'SMB1Protocol',
'FaxServer',
'InternetPrintClient'
)
foreach ($f in $unusedFeatures) {
$feat = Get-WindowsFeature -Name $f
if ($feat.Installed) { Uninstall-WindowsFeature $f }
}
Saving and Replicating Role Configuration
# Export installed roles/features to XML for documentation or replication
Get-WindowsFeature | Where-Object {$_.Installed -eq $true} |
Export-Clixml 'C:Configinstalled_features.xml'
# On a new server — install the same roles from the saved list
$saved = Import-Clixml 'C:Configinstalled_features.xml'
$rolesToInstall = $saved | Where-Object {$_.FeatureType -eq 'Role'} |
Select-Object -ExpandProperty Name
Install-WindowsFeature $rolesToInstall -IncludeManagementTools
Verifying Installed Roles
# Quick summary of installed roles
Get-WindowsFeature | Where-Object {$_.Installed -eq $true} |
Select-Object Name,DisplayName,FeatureType |
Sort-Object FeatureType,Name | Format-Table -AutoSize
# Check if a specific role is installed
(Get-WindowsFeature -Name 'Web-Server').Installed
# View role installation history in event log
Get-WinEvent -LogName 'Microsoft-Windows-ServerManager-DeploymentProvider/Operational' -MaxEvents 20
Summary
Windows Server 2012 R2 roles and features are fully manageable through PowerShell’s Install-WindowsFeature and Uninstall-WindowsFeature cmdlets. Using PowerShell for role management enables infrastructure as code — you can capture exactly what is installed on one server and precisely replicate it on another. Always add only the roles your server needs to minimise the attack surface and reduce the number of Windows Update patches required.