View, Add Or Remove Windows Features Via PowerShell
- By : Dom
- Category : Scripting
- Tags: Powershell
PowerShell is Microsoft’s scripting language based around the .NET Framework. It’s mainly used for administering and configuring local and remote systems and you can also use it for the same task of viewing, adding or removing optional Windows features. It’s possible to use the DISM tool directly in Powershell but there’s also a set of integrated commands that work in a similar way.
PowerShell Optional Features In Windows 8.1 And 10
Newer versions of Windows have the function to view optional features built in. Make sure to run PowerShell as administrator or the commands won’t work. To view the list of features available on the system.
get-windowsoptionalfeature -online | ft | more
Like DISM, the online argument tells the command to work on the local system while the optional ft displays the results in a table and more breaks the list into pages. To filter the list into enabled or disabled features.
get-windowsoptionalfeature -online | where state -like disabled* | ft | more
get-windowsoptionalfeature -online | where state -like enabled* | ft | more
The where statement checks the state of the feature and filters the list accordingly. The reason to use -like and the * wildcard is some features don’t match the words exactly. For example, NetFx3 has a default state of DisabledWithPayloadRemoved which means the feature is disabled and its files are not on the system. As a result only “-like disabled” won’t show it in the list.
With PowerShell it’s no problem to use a similar command for filtering the list with specific keywords. The below example will show only the features that have the word “hyper-v” in their name.
get-windowsoptionalfeature -online | where featurename -like *hyper-v* | ft
To get more detailed information about a specific feature:
get-windowsoptionalfeature -online -featurename [feature name]
This is very similar to DISM’s get-featureinfo argument although feature names are not case sensitive here. You can also use wildcards to list several features at once. The following command will get information on all features with “media” in the name.
get-windowsoptionalfeature -online -featurename *media*
Adding or removing a feature is a pretty simple process:
enable-windowsoptionalfeature -online -featureName [feature name] -all
disable-windowsoptionalfeature -online -featureName [feature name]
The optional -all argument automatically adds any other features that are required for the feature you specified to work. By using two commands on the same line you can enable or disable multiple features at once
get-windowsoptionalfeature -online -featurename *hyper-v* | enable-windowsoptionalfeature -online -norestart
The above command first filters all features with “Hyper-V” in their name. Then those feature names are piped to the enable command to be enabled one after the other without rebooting. This causes seven Hyper-V features to be enabled in Windows 10 with a single line.
Like other Powershell commands, feature names for enabling or disabling are not case sensitive.
https://www.raymond.cc/blog/add-or-remove-windows-features-through-the-command-prompt/
No Comments