How to remove windows features using PowerShell?


To remove windows features, we can use command Remove-WindowsFeature command is used along with feature name.

Remove-WindowsFeature Search-Service -Verbose
VERBOSE: Uninstallation started...
VERBOSE: Continue with removal?
VERBOSE: Prerequisite processing started...
VERBOSE: Prerequisite processing succeeded.
Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
True No Success {Windows Search Service}
VERBOSE: Uninstallation succeeded.

If the windows feature has the management tools like as in Web-Server (IIS) feature, you can add the same in the command line. If the server requires restart then you can add the -Restart parameter. For example,

Remove-WindowsFeature Web-Server -IncludeManagementTools -Restart -Verbose

If we check the -Name parameter, it supports the string array. This means we can remove multiple roles and features together.

help Remove-WindowsFeature -Parameter Name -Name <Feature[]>

Example of removal of multiple features together and with -LogPath parameter to log the output on the local computer.

PS C:\Users\Administrator> Remove-WindowsFeature Windows-Server-Backup, Search-Service -LogPath C:\Temp\Uninstallfeatures.txt -Verbose
VERBOSE: Uninstallation started...
VERBOSE: Continue with removal?
VERBOSE: Prerequisite processing started...
VERBOSE: Prerequisite processing succeeded.
Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
True No Success {Windows Search Service, Windows Server Ba...
VERBOSE: Uninstallation succeeded.

To remove windows features on the remote computer, you need to use -ComputerName parameter. For example,

Remove-WindowsFeature Windows-Server-Backup, Search-Service -ComputerName Test1-Win2k16 -Verbose

Output

PS C:\Scripts\IISRestart> Remove-WindowsFeature Windows-Server-Backup, Search-Service -ComputerName Test1-Win2k16 -Verbose
VERBOSE: Uninstallation started...
VERBOSE: Continue with removal?
VERBOSE: Prerequisite processing started...
VERBOSE: Prerequisite processing succeeded.

Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
True No Success {Windows Search Service, Windows Server Ba...
VERBOSE: Uninstallation succeeded.

This -ComputerName parameter is a string parameter, not an array as shown below with the help command.

help Remove-WindowsFeature -Parameter ComputerName -ComputerName [<String≫]

So to remove the windows features from the multiple computers, we need to use the foreach loop and -ComputerName parameter or through the Invoke-Command. Using Invoke-Command will be easier.

Invoke-Command -ComputerName Test1-Win2k16,Test1-Win2k12 -ScriptBlock{Remove-WindowsFeature Windows-Server-Backup,Search-Service}

The above command will ensure to remove multiple features on the multiple remote computers.

Updated on: 26-Aug-2020

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements