View, Add Or Remove Windows Features Via PowerShell

Scripting

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scripting
Install Vmware PowerCLI

PowerCLI is really easy to install now. From an Administrative Powershell window just enter: Install-Module -Name VMware.PowerCLI Minimum Powershell Version must be v3.   Offline Install of PowerCLI Accessing the PowerCLI Modules We’re now ready to download the PowerCLI modules. This task will require a system with internet access. This …

Scripting
Pass credentials with Powershell – 3 Ways

Interactive Here’s your typical scenario.   You have a script that requires credentials internally.  So to provide those credentials you would do something like $MyCredentials=GET-CREDENTIAL –credential “CONTOSO\Username” and you of course see a box like this normally on the screen Then you would type in the password and life would go …

Deployment
MDT – Joining a Computer to a Domain Using PowerShell

Using PowerShell scripts within a task sequence provides more flexibility than using the CustomSettings.ini file to join a computer to a domain. The parameters of the CustomSettings.ini file are common to any deployment you perform. That’s why creating a custom PowerShell script to join your domain will be customize to …