Install WindowsFeature - PowerShell


Overview

Install-WindowsFeature lets you add Windows features to your system. It’s used in various scenarios, including enabling optional Windows roles and enabling .NET Framework features.

Syntax

Install-WindowsFeature [-Name] <string[]> [-Source] <string> [-Restart] [-ErrorAction] <ActionPreference> [-WarningAction] <ActionPreference> [-Force] [-Credential] <PSCredential> [-IncludeAllSubFeatures] [-ExcludeAllSubFeatures] [-All] [-LimitAccess] [-FeatureData] <string> [-LogPath] <string>

Options/Flags

  • -Name: Specifies the Windows feature(s) to install. You can specify multiple features by separating them with commas.
  • -Source: Specifies the path to a WIM or ISO file containing the Windows features. If not specified, it uses the default source.
  • -Restart: Indicates whether to restart the computer after installation, only if required.
  • -ErrorAction: Specifies how errors are handled. Valid values include: Continue, Stop, SilentlyContinue.
  • -WarningAction: Specifies how warnings are handled. Valid values include: Continue, Stop, SilentlyContinue.
  • -Force: Forces the installation even if the system is not ready.
  • -Credential: Specifies the credentials to use for the installation.
  • -IncludeAllSubFeatures: Includes all sub-features of the specified feature.
  • -ExcludeAllSubFeatures: Excludes all sub-features of the specified feature.
  • -All: Installs all available Windows features.
  • -LimitAccess: Limits access to the installed features.
  • -FeatureData: Specifies additional data to be passed to the installation.
  • -LogPath: Specifies the path to a log file to record the installation progress.

Examples

Install a single feature:

Install-WindowsFeature -Name Telnet-Client

Install multiple features:

Install-WindowsFeature -Name Telnet-Client,SNMP-Service

Install a feature from a specific source:

Install-WindowsFeature -Name Telnet-Client -Source C:\sources\install.wim

Restart the computer after installation:

Install-WindowsFeature -Name Telnet-Client -Restart

Common Issues

  • Insufficient permissions: Ensure you have administrative privileges to install Windows features.
  • Feature not found: Check that the specified feature name is correct and that it’s available on your system.
  • Restart required: Some features require a system restart to complete the installation. If prompted, restart your computer.

Integration

Using Get-WindowsFeature:

$features = Get-WindowsFeature

Install-WindowsFeature -Name $features.Name
  • Dism: Manages Windows images, including installing and removing features.
  • Enable-WindowsOptionalFeature: Enables optional Windows features without installing them.