Different ways for installing Windows features on the command line

2 July 2015
To install a certain Windows feature on the command line there are many options, which one should one use?
Platform Support

Vista+2008 Win7 2008 R2 Win8.* 2012 R* Win10 2016 Nano Source
Enable-WindowsOptionalFeature * * * * * Dism module
Get-WindowsOptionalFeature * * * * * Dism module
Install-WindowsFeature * * ServerManager module
Get-WindowsFeature * * * ServerManager module
Add-WindowsFeature * A A ServerManager module
dism.exe * * * * * * * %SystemRoot%\System32
pkgmgr.exe * * * * * * * * %SystemRoot%\System32
A = An alias for Install-WindowsFeature

So the Server-Manager cmdlets are only available on servers or maybe if you install the remote administration tools on a workstation. If you need to support client computers as well use the Dism cmdlets, to be completely on the safe side, use dism.exe. And if you still support Vista/Server 2008 look into pkgmgr.exe

Why are there two different sets of PowerShell cmdlets?

Good question, my guess is that there were two distinct teams at Microsoft. The Server-Manager team created cmdlets to support features in Server-Manager. The dism team (?) wanted to replicate the functionality of dism.exe. By the time they found out about each other, nobody wanted to give up their code.

Different Features

Lets look at the commands in details:

 Install-WindowsFeature [-Name] <Feature[]> [-ComputerName <String>] [-Credential <PSCredential>]
 [-IncludeAllSubFeature] [-IncludeManagementTools] [-LogPath <String>] [-Restart] [-Source <String[]>] [-Confirm]
 [-WhatIf] [<CommonParameters>]

 Install-WindowsFeature [-ComputerName <String>] [-Credential <PSCredential>] [-LogPath <String>] [-Restart]
 [-Source <String[]>] [-Vhd <String>] -ConfigurationFilePath <String> [-Confirm] [-WhatIf] [<CommonParameters>]

 Install-WindowsFeature [-Name] <Feature[]> [-ComputerName <String>] [-Credential <PSCredential>]
 [-IncludeAllSubFeature] [-IncludeManagementTools] [-LogPath <String>] [-Source <String[]>] -Vhd <String>
 [-Confirm] [-WhatIf] [<CommonParameters>]
compared to:
 Enable-WindowsOptionalFeature [-All] [-LimitAccess] [-LogLevel <LogLevel>] [-LogPath <String>] [-NoRestart]
 [-PackageName <String>] [-ScratchDirectory <String>] [-Source <String[]>] [-SystemDrive <String>]
 [-WindowsDirectory <String>] -FeatureName <String[]> -Online [<CommonParameters>]

 Enable-WindowsOptionalFeature [-All] [-LimitAccess] [-LogLevel <LogLevel>] [-LogPath <String>] [-NoRestart]
 [-PackageName <String>] [-ScratchDirectory <String>] [-Source <String[]>] [-SystemDrive <String>]
 [-WindowsDirectory <String>] -FeatureName <String[]> -Path <String> [<CommonParameters>]

One big difference is that the Server-Manager cmdlets can work against remote computers as well, while dism works only locally but can target offline Windows installations.

Install-WindowsFeature supports a nice trick, if you want to know what other features are installed, use the '-whatif' switch. This works when using -IncludeAllSubFeature but also when installing roles, it just lists all sub-features it would install. The same works for UnInstall-WindowsFeature, try

UnInstall-WindowsFeature -Name NET-Framework-45-Features -whatif
and you can see that you better not remove the dot.NET framework.

Different Windows feature names
Both sets of cmdlets use their own feature names :-(. The dism module cmdlets use the same names as dism.exe, so if you have used those before, just keep using them. The Server Manager uses different names. The following tests were done on a Server 2012 R2
get-windowsfeature | select Name | sort name
returns 267 features.
Get-WindowsOptionalFeature -Online | Select FeatureName | Sort FeatureName
returns 311 features, exactly the same as:
dism.exe -online -get-features
List of Windows feature names
*-WindowsOptionalFeature
(Dism)
*-WindowsFeature
(Server-Manager)
ActiveDirectory-PowerShell 
ADCertificateServicesManagementTools 
ADCertificateServicesRole 
AdminUI 
Application-Server 
Application-Server-HTTP-Activation 
Application-Server-MSMQ-Activation 
Application-Server-Pipe-Activation 
Application-Server-TCP-Activation 
Application-Server-TCP-Port-Sharing 
Application-Server-WAS-Support 
Application-Server-WebServer-Support 
AppServer 
AS-Dist-Transaction 
AS-Ent-Services 
AS-Incoming-Trans 
AS-NET-Framework 
AS-Outgoing-Trans 
AS-WS-Atomic 
AuthManager 
BdeAducExtTool 
BiometricFramework 
BitLocker 
BitLocker-NetworkUnlock 
BitLocker-RemoteAdminTool 
Bitlocker-Utilities 
BITS 
BITSExtensions-AdminPack 
BITSExtensions-Upload 
BusScan-ScanServer 
CCFFilter 
CertificateEnrollmentPolicyServer 
CertificateEnrollmentServer 
CertificateServices 
CertificateServicesManagementTools 
ClientForNFS-Infrastructure 
CoreFileServer 
CoreFileServer-RSAT 
DamgmtTools 
DataCenterBridging 
Dedup-Core 
DesktopExperience 
DfsMgmt 
DFSN-Server 
DFSR-Infrastructure-ServerEdition 
DHCPServer 
DHCPServer-Tools 
DirectoryServices-ADAM 
DirectoryServices-ADAM-Tools 
DirectoryServices-AdministrativeCenter 
DirectoryServices-DomainController 
DirectoryServices-DomainController-Tools 
DirectoryServices-ISM-Smtp 
DirectPlay 
DNS-Server-Full-Role 
DNS-Server-Tools 
DSC-Service 
EnhancedStorage 
FailoverCluster-AdminPak 
FailoverCluster-AutomationServer 
FailoverCluster-CmdInterface 
FailoverCluster-FullServer 
FailoverCluster-Mgmt 
FailoverCluster-PowerShell 
FaxServiceConfigRole 
FaxServiceRole 
FileAndStorage-Services 
FileServerVSSAgent 
File-Services 
File-Services-Search-Service 
FRS-Infrastructure 
FSRM-Infrastructure 
FSRM-Infrastructure-Services 
FSRM-Management 
Gateway 
Gateway-UI 
HCAP-Server 
HCSRuntime 
HCSUI 
IAS NT Service 
IdentityServer-SecurityTokenService 
IIS-ApplicationDevelopment 
IIS-ApplicationInit 
IIS-ASP 
IIS-ASPNET 
IIS-ASPNET45 
IIS-BasicAuthentication 
IIS-CertProvider 
IIS-CGI 
IIS-ClientCertificateMappingAuthentication 
IIS-CommonHttpFeatures 
IIS-CustomLogging 
IIS-DefaultDocument 
IIS-DigestAuthentication 
IIS-DirectoryBrowsing 
IIS-FTPExtensibility 
IIS-FTPServer 
IIS-FTPSvc 
IIS-HealthAndDiagnostics 
IIS-HostableWebCore 
IIS-HttpCompressionDynamic 
IIS-HttpCompressionStatic 
IIS-HttpErrors 
IIS-HttpLogging 
IIS-HttpRedirect 
IIS-HttpTracing 
IIS-IIS6ManagementCompatibility 
IIS-IISCertificateMappingAuthentication 
IIS-IPSecurity 
IIS-ISAPIExtensions 
IIS-ISAPIFilter 
IIS-LegacyScripts 
IIS-LegacySnapIn 
IIS-LoggingLibraries 
IIS-ManagementConsole 
IIS-ManagementScriptingTools 
IIS-ManagementService 
IIS-Metabase 
IIS-NetFxExtensibility 
IIS-NetFxExtensibility45 
IIS-ODBCLogging 
IIS-Performance 
IIS-RequestFiltering 
IIS-RequestMonitor 
IIS-Security 
IIS-ServerSideIncludes 
IIS-StaticContent 
IIS-URLAuthorization 
IIS-WebDAV 
IIS-WebServer 
IIS-WebServerManagementTools 
IIS-WebServerRole 
IIS-WebSockets 
IIS-WindowsAuthentication 
IIS-WMICompatibility 
InkAndHandwritingServices 
Internet-Explorer-Optional-amd64 
IPAMClientFeature 
IPAMServerFeature 
iSCSITargetServer 
iSCSITargetServer-PowerShell 
iSCSITargetStorageProviders 
iSNS_Service 
KeyDistributionService-PSH-Cmdlets 
LegacyComponents 
Licensing 
Licensing-Diagnosis-UI 
Licensing-UI 
LightweightServer 
ManagementOdata 
MediaPlayback 
Microsoft-Hyper-V 
Microsoft-Hyper-V-Management-Clients 
Microsoft-Hyper-V-Management-PowerShell 
Microsoft-Hyper-V-Offline 
Microsoft-Hyper-V-Online 
Microsoft-Windows-Deployment-Services 
Microsoft-Windows-Deployment-Services-Admin-Pack 
Microsoft-Windows-Deployment-Services-Deployment-Server 
Microsoft-Windows-Deployment-Services-Legacy-SIS 
Microsoft-Windows-Deployment-Services-Transport-Server 
Microsoft-Windows-FCI-Client-Package 
Microsoft-Windows-GroupPolicy-ServerAdminTools-Update 
MicrosoftWindowsPowerShell 
MicrosoftWindowsPowerShellISE 
MicrosoftWindowsPowerShellRoot 
MicrosoftWindowsPowerShellV2 
Microsoft-Windows-ServerEssentials-ServerSetup 
Microsoft-Windows-Web-Services-for-Management-IIS-Extension 
MSMQ 
MSMQ-ADIntegration 
MSMQ-DCOMProxy 
MSMQ-HTTP 
MSMQ-Multicast 
MSMQ-RoutingServer 
MSMQ-Server 
MSMQ-Services 
MSMQ-Triggers 
MSRDC-Infrastructure 
MultipathIo 
NetFx3 
NetFx3ServerFeatures 
NetFx4 
NetFx4Extended-ASPNET45 
NetFx4ServerFeatures 
NetworkDeviceEnrollmentServices 
NetworkLoadBalancingFullServer 
NetworkLoadBalancingManagementClient 
NFS-Administration 
NIS 
NPAS-Role 
NPSManagementTools 
OEM-Appliance-OOBE 
OnlineRevocationServices 
OnlineRevocationServicesManagementTools 
P2P-PnrpOnly 
PeerDist 
PKIClient-PSH-Cmdlets 
Printing-AdminTools-Collection 
Printing-Client 
Printing-Client-Gui 
Printing-InternetPrinting-Client 
Printing-InternetPrinting-Server 
Printing-LPDPrintService 
Printing-LPRPortMonitor 
Printing-Server-Foundation-Features 
Printing-Server-Role 
Printing-XPSServices-Features 
PSync 
QWAVE 
RasCMAK 
RasRoutingProtocols 
RasServerAdminTools 
RemoteAccess 
RemoteAccessMgmtTools 
RemoteAccessPowerShell 
RemoteAccessServer 
RemoteAssistance 
Remote-Desktop-Services 
ResumeKeyFilter 
RightsManagementServices 
RightsManagementServices-AdminTools 
RightsManagementServicesManagementTools 
RightsManagementServices-Role 
RMS-Federation 
RPC-HTTP_Proxy 
RSAT 
RSAT-ADDS-Tools-Feature 
RSAT-AD-Tools-Feature 
RSAT-Hyper-V-Tools-Feature 
RSAT-NIS 
RSAT-RDS-Tools-Feature 
SBMgr-UI 
SearchEngine-Server-Package 
Security-SPP-Vmw 
ServerCore-Drivers-General 
ServerCore-EA-IME 
ServerCore-EA-IME-WOW64 
ServerCore-FullServer 
ServerCore-WOW64 
Server-Drivers-General 
Server-Drivers-Printers 
ServerForNFS-Infrastructure 
Server-Gui-Mgmt 
Server-Gui-Shell 
ServerManager-Core-RSAT 
ServerManager-Core-RSAT-Feature-Tools 
ServerManager-Core-RSAT-Role-Tools 
Server-Manager-RSAT-File-Services 
ServerMediaFoundation 
ServerMigration 
Server-Psh-Cmdlets 
Server-RSAT-SNMP 
ServicesForNFS-ServerAndClient 
SessionDirectory 
SimpleTCP 
SIS-Limited 
SMB1Protocol 
SMBBW 
SmbDirect 
SMBHashGeneration 
SmbWitness 
Smtpsvc-Admin-Update-Name 
Smtpsvc-Service-Update-Name 
SNMP 
Storage-Services 
TelnetClient 
TelnetServer 
TFTP 
TIFFIFilter 
TlsSessionTicketKey-PSH-Cmdlets 
UpdateServices 
UpdateServices-API 
UpdateServices-Database 
UpdateServices-RSAT 
UpdateServices-Services 
UpdateServices-UI 
UpdateServices-WidDatabase 
User-Interfaces-Infra 
VmHostAgent 
VolumeActivation-Full-Role 
WAS-ConfigurationAPI 
WAS-NetFxEnvironment 
WAS-ProcessModel 
WAS-WindowsActivationService 
WCF-HTTP-Activation 
WCF-HTTP-Activation45 
WCF-MSMQ-Activation45 
WCF-NonHTTP-Activation 
WCF-Pipe-Activation45 
WCF-Services45 
WCF-TCP-Activation45 
WCF-TCP-PortSharing45 
WebAccess 
Web-Application-Proxy 
WebEnrollmentServices 
WindowsFeedbackForwarder 
Windows-Identity-Foundation 
Windows-Internal-Database 
WindowsMediaPlayer 
WindowsPowerShellWebAccess 
WindowsServerBackup 
WindowsServerBackupSnapin 
WindowsStorageManagementService 
WINSRuntime 
WINS-Server-Tools 
WirelessNetworking 
WMISnmpProvider 
WorkFolders-Server 
WSS-Product-Package 
Xps-Foundation-Xps-Viewer


AD-Certificate 
ADCS-Cert-Authority 
ADCS-Device-Enrollment 
ADCS-Enroll-Web-Pol 
ADCS-Enroll-Web-Svc 
ADCS-Online-Cert 
ADCS-Web-Enrollment 
AD-Domain-Services 
ADFS-Federation 
ADLDS 
ADRMS 
ADRMS-Identity 
ADRMS-Server 
Application-Server 
AS-Dist-Transaction 
AS-Ent-Services 
AS-HTTP-Activation 
AS-Incoming-Trans 
AS-MSMQ-Activation 
AS-Named-Pipes 
AS-NET-Framework 
AS-Outgoing-Trans 
AS-TCP-Activation 
AS-TCP-Port-Sharing 
AS-WAS-Support 
AS-Web-Support 
AS-WS-Atomic 
Biometric-Framework 
BitLocker 
BitLocker-NetworkUnlock 
BITS 
BITS-Compact-Server 
BITS-IIS-Ext 
BranchCache 
CMAK 
Data-Center-Bridging 
Desktop-Experience 
DHCP 
DirectAccess-VPN 
Direct-Play 
DNS 
DSC-Service 
EnhancedStorage 
Failover-Clustering 
Fax 
FileAndStorage-Services 
File-Services 
FS-BranchCache 
FS-Data-Deduplication 
FS-DFS-Namespace 
FS-DFS-Replication 
FS-FileServer 
FS-iSCSITarget-Server 
FS-NFS-Service 
FS-Resource-Manager 
FS-SMB1 
FS-SMBBW 
FS-SyncShareService 
FS-VSS-Agent 
GPMC 
Hyper-V 
Hyper-V-PowerShell 
Hyper-V-Tools 
InkAndHandwritingServices 
Internet-Print-Client 
IPAM 
IPAM-Client-Feature 
iSCSITarget-VSS-VDS 
ISNS 
LPR-Port-Monitor 
ManagementOdata 
Migration 
MSMQ 
MSMQ-DCOM 
MSMQ-Directory 
MSMQ-HTTP-Support 
MSMQ-Multicasting 
MSMQ-Routing 
MSMQ-Server 
MSMQ-Services 
MSMQ-Triggers 
Multipath-IO 
NET-Framework-45-ASPNET 
NET-Framework-45-Core 
NET-Framework-45-Features 
NET-Framework-Core 
NET-Framework-Features 
NET-HTTP-Activation 
NET-Non-HTTP-Activ 
NET-WCF-HTTP-Activation45 
NET-WCF-MSMQ-Activation45 
NET-WCF-Pipe-Activation45 
NET-WCF-Services45 
NET-WCF-TCP-Activation45 
NET-WCF-TCP-PortSharing45 
NFS-Client 
NLB 
NPAS 
NPAS-Health 
NPAS-Host-Cred 
NPAS-Policy-Server 
PNRP 
PowerShell 
PowerShell-ISE 
PowerShellRoot 
PowerShell-V2 
Print-Internet 
Print-LPD-Service 
Print-Scan-Server 
Print-Server 
Print-Services 
qWave 
RDC 
RDS-Connection-Broker 
RDS-Gateway 
RDS-Licensing 
RDS-Licensing-UI 
RDS-RD-Server 
RDS-Virtualization 
RDS-Web-Access 
RemoteAccess 
Remote-Assistance 
Remote-Desktop-Services 
Routing 
RPC-over-HTTP-Proxy 
RSAT 
RSAT-AD-AdminCenter 
RSAT-ADCS 
RSAT-ADCS-Mgmt 
RSAT-ADDS 
RSAT-ADDS-Tools 
RSAT-ADLDS 
RSAT-AD-PowerShell 
RSAT-ADRMS 
RSAT-AD-Tools 
RSAT-Bits-Server 
RSAT-Clustering 
RSAT-Clustering-AutomationServer 
RSAT-Clustering-CmdInterface 
RSAT-Clustering-Mgmt 
RSAT-Clustering-PowerShell 
RSAT-CoreFile-Mgmt 
RSAT-DFS-Mgmt-Con 
RSAT-DHCP 
RSAT-DNS-Server 
RSAT-Fax 
RSAT-Feature-Tools 
RSAT-Feature-Tools-BitLocker 
RSAT-Feature-Tools-BitLocker-BdeAducExt 
RSAT-Feature-Tools-BitLocker-RemoteAdminTool 
RSAT-File-Services 
RSAT-FSRM-Mgmt 
RSAT-Hyper-V-Tools 
RSAT-NFS-Admin 
RSAT-NIS 
RSAT-NLB 
RSAT-NPAS 
RSAT-Online-Responder 
RSAT-Print-Services 
RSAT-RDS-Gateway 
RSAT-RDS-Licensing-Diagnosis-UI 
RSAT-RDS-Tools 
RSAT-RemoteAccess 
RSAT-RemoteAccess-Mgmt 
RSAT-RemoteAccess-PowerShell 
RSAT-Role-Tools 
RSAT-SMTP 
RSAT-SNMP 
RSAT-VA-Tools 
RSAT-WINS 
Search-Service 
ServerEssentialsRole 
Server-Gui-Mgmt-Infra 
Server-Gui-Shell 
Server-Media-Foundation 
Simple-TCPIP 
SMTP-Server 
SNMP-Service 
SNMP-WMI-Provider 
Storage-Services 
Telnet-Client 
Telnet-Server 
TFTP-Client 
UpdateServices 
UpdateServices-API 
UpdateServices-DB 
UpdateServices-RSAT 
UpdateServices-Services 
UpdateServices-UI 
UpdateServices-WidDB 
User-Interfaces-Infra 
VolumeActivation 
WAS 
WAS-Config-APIs 
WAS-NET-Environment 
WAS-Process-Model 
WDS 
WDS-AdminPack 
WDS-Deployment 
WDS-Transport 
Web-App-Dev 
Web-AppInit 
Web-Application-Proxy 
Web-ASP 
Web-Asp-Net 
Web-Asp-Net45 
Web-Basic-Auth 
Web-Cert-Auth 
Web-CertProvider 
Web-CGI 
Web-Client-Auth 
Web-Common-Http 
Web-Custom-Logging 
Web-DAV-Publishing 
Web-Default-Doc 
Web-Digest-Auth 
Web-Dir-Browsing 
Web-Dyn-Compression 
Web-Filtering 
Web-Ftp-Ext 
Web-Ftp-Server 
Web-Ftp-Service 
Web-Health 
Web-Http-Errors 
Web-Http-Logging 
Web-Http-Redirect 
Web-Http-Tracing 
Web-Includes 
Web-IP-Security 
Web-ISAPI-Ext 
Web-ISAPI-Filter 
Web-Lgcy-Mgmt-Console 
Web-Lgcy-Scripting 
Web-Log-Libraries 
Web-Metabase 
Web-Mgmt-Compat 
Web-Mgmt-Console 
Web-Mgmt-Service 
Web-Mgmt-Tools 
Web-Net-Ext 
Web-Net-Ext45 
Web-ODBC-Logging 
Web-Performance 
Web-Request-Monitor 
Web-Scripting-Tools 
Web-Security 
Web-Server 
Web-Stat-Compression 
Web-Static-Content 
Web-Url-Auth 
Web-WebServer 
Web-WebSockets 
Web-WHC 
Web-Windows-Auth 
Web-WMI 
WFF 
Windows-Identity-Foundation 
Windows-Internal-Database 
WindowsPowerShellWebAccess 
Windows-Server-Backup 
WindowsStorageManagementService 
Windows-TIFF-IFilter 
WinRM-IIS-Ext 
WINS 
Wireless-Networking 
WoW64-Support 
XPS-Viewer 
dism.exe and PowerShell
In case you decided to support older Windows versions without support for the PowerShell cmdlets, you will use dism.exe to install optional features. Here's a bit of PowerShell code check whether a feature is installed:
$tempFile = "$env:temp\tempName.log"
& dism.exe /online /get-features /format:table | out-file $tempFile -Force       
$WinFeatures = (Import-CSV -Delim '|' -Path $tempFile -Header Name,state | Where-Object {$_.State -eq "Enabled "}) | Select Name
Remove-Item -Path $tempFile 
You now have a list of all installed feature-names, you can check for the existence of a feature like this:
if(($WinFeatures | Where-Object {$_.Name.Trim() -eq "WirelessNetworking"}) -eq $null) {...}
Tags: IT Pro

Pages in this section

Categories

ASP.Net | Community | Development | IIS | IT Pro | Security | SQL (Server) | Tools | Web | Work on the road | Windows