Uninstall WindowsFeature - PowerShell
Overview
The Uninstall-WindowsFeature
command removes optional Windows features from a system. It can be used to free up disk space, improve performance by reducing unnecessary services and dependencies, or customize a Windows installation.
Syntax
Uninstall-WindowsFeature [-Name] <string[]> [-Restart] [-Force]
[-ComputerName <string>] [-Credential <PSCredential>] [<CommonParameters>]
Options/Flags
| Option/Flag | Description |
|—|—|
| -Name | Specifies the name of the feature to be uninstalled. Multiple feature names can be specified as an array of strings. |
| -Restart | Automatically restarts the computer after the feature is uninstalled. This is necessary for some features to take effect. |
| -Force | Uninstalls the feature even if it is required by other features. Use with caution, as this may cause unexpected behavior or system instability. |
| -ComputerName | Specifies the remote computer on which to uninstall the feature. By default, the command operates on the local computer. |
| -Credential | Specifies the credentials to use when performing the operation on a remote computer. |
Examples
Simple: Uninstall the Hyper-V feature
Uninstall-WindowsFeature -Name Hyper-V
Complex: Uninstall multiple features and restart the computer
Uninstall-WindowsFeature -Name "Telnet-Client" "Fax-Services" -Restart
Remote Uninstallation: Uninstall a feature on a remote computer
Uninstall-WindowsFeature -Name "Windows-Defender" -ComputerName remote-pc -Credential domain\username
Common Issues
- Restart Required: Some features require a computer restart after uninstallation. The
-Restart
flag can be used to automate this process. - Dependencies: Uninstalling a feature may remove dependencies for other features, causing them to fail. Use the
-Force
flag with caution. - File Removal: Uninstalling a feature may not remove all associated files. These files can be manually deleted or cleaned up using a tool like DISM.
Integration
- Get-WindowsFeature: Query which features are installed or available for installation.
- Install-WindowsFeature: Install a new Windows feature.
- Export-WindowsFeature: Export a feature configuration for later installation.