Add WindowsFeature - PowerShell
Overview
Add-WindowsFeature is a PowerShell command used to install and enable optional Windows features, such as roles, services, or components. It simplifies the process of adding features to a Windows system without the need for manual configuration or GUI interactions.
Syntax
Add-WindowsFeature [-Name] <String[]> [-IncludeManagementTools] [-LogPath] <String> [-Restart] [-WhatIf]
Options/Flags
- -Name (Required): Specifies the name of the feature(s) to be installed. Multiple features can be listed separated by commas.
- -IncludeManagementTools (Optional): Includes management tools for the installed feature(s). Default:
False
- -LogPath (Optional): Specifies the path to a log file where the installation progress will be recorded. Default: None
- -Restart (Optional): Automatically restarts the computer after installation if necessary. Default:
False
- -WhatIf (Optional): Shows what the command would do without actually performing the action.
Examples
Example 1: Installing a Single Feature
Add-WindowsFeature -Name "Telnet-Client"
Example 2: Installing Multiple Features with Management Tools
Add-WindowsFeature -Name "Remote-Server-Administration-Tools", "Windows-PowerShell" -IncludeManagementTools
Example 3: Installation with Logging and Restart
Add-WindowsFeature -Name "Hyper-V" -LogPath "C:\WindowsFeatureInstallation.log" -Restart
Common Issues
- Feature not Found: Verify that the specified feature name is correct and that it’s available for your Windows version.
- Installation Failed: Check the log file (if specified) or Event Viewer for error details. Ensure the required dependencies are met.
- Computer Restart Required: Remember to manually restart the computer if the -Restart option was not used.
Integration
Add-WindowsFeature can be integrated with other commands to automate feature installation and configuration.
# Install Hyper-V and enable Hyper-V management tools
Add-WindowsFeature -Name Hyper-V -IncludeManagementTools | Enable-WindowsOptionalFeature -Online
Related Commands
- Enable-WindowsOptionalFeature: Enables installed features.
- Get-WindowsFeature: Gets information about installed Windows features.
- Remove-WindowsFeature: Uninstalls Windows features.