Category filter
Script to enable or disable Windows optional features
In Windows, optional features encompass additional software components or functionalities that you can install or uninstall according to your requirements and preferences. Windows provides a multitude of optional features, and the availability varies depending on the version of Windows in use. However, not all these optional features are essential for a standard user. For instance, the optional feature “XPS Services” is designed for printing and managing XPS documents. If a user does not work with XPS files, these services may not hold significant utility. Nevertheless, advanced users may find some of these features to be genuinely valuable.
These features can be enabled or disabled on the device by navigating to the Start Menu > Control Panel > Programs and Features > Turn Windows features on or off. However, this may not be feasible for IT admins to carry out on numerous devices. In such cases, Hexnode’s Execute Custom Script action can assist in getting, enabling, or disabling Windows features by pushing scripts from the console.
The following scripts use the Deployment Image Servicing and Management (DISM) tool, a command-line tool used to modify Windows images.
Get all Windows optional features
The Batch and PowerShell script provided below fetches the list of all available optional features along with their enabled/disabled status on the device. The online parameter indicates that the command affects the features that are currently available on the running operating system.
Batch script
1 |
Dism /online /Get-Features /format:table | more |
PowerShell script
1 |
get-windowsoptionalfeature -online | ft | more |
Get a detailed info on a Windows optional feature
The given Batch and PowerShell scripts retrieve a detailed description of the feature specified as FeatureName. For instance, the script mentioned below provides the detailed description of the Windows optional feature called “Containers”.
Batch script
1 |
Dism /online /Get-FeatureInfo /FeatureName:Containers |
PowerShell script
1 |
get-windowsoptionalfeature -online -featurename *containers* |
Please note that the feature name for which the detailed description needs to be fetched should be enclosed in asterisks ‘* *’, as shown in the above script.
Get a list of all enabled Windows optional features
The scripts provided below retrieve a list of all enabled Windows optional features.
Batch script
1 |
Dism /online /Get-Features /format:table | findstr "Enabled" | more |
PowerShell script
1 |
get-windowsoptionalfeature -online | where state -like enabled* | ft | more |
In the above script, the part where state -like enabled* filters the output by selecting only the features whose state is “enabled”.
where
– This command is used to filter objects based on a specific condition.
-like
– This operator performs a wildcard match.
ft
– It is the “Format-Table” command, which formats the output as a table.
more
– This command allows the output to be displayed page by page, pausing after each screenful of information is displayed. It helps in viewing long or multiple results by scrolling through them.
Get a list of all disabled Windows optional features
The scripts provided below retrieve a list of all disabled Windows optional features.
Batch script
1 |
Dism /online /Get-Features /format:table | findstr "Disabled" | more |
PowerShell script
1 |
get-windowsoptionalfeature -online | where state -like disabled* | ft | more |
Enable a Windows optional feature
The scripts provided below are used to enable Windows optional features.
Batch script
1 |
Dism /online /Enable-Feature /FeatureName:Containers /All |
The above script enables a Windows optional feature along with all the related features that are required for it to work. By using the All argument, you can enable all the associated features. If this argument is omitted, only the feature mentioned as FeatureName will be enabled.
PowerShell script
1 |
enable-windowsoptionalfeature -online -featureName containers -all -NoRestart |
The above script enables a Windows feature along with all the related features that are required for it to work. The NoRestart argument suppresses the reboot action.
Disable a Windows optional feature
The scripts provided below are used to disable Windows optional features.
Batch script
1 |
Dism /online /Disable-Feature /FeatureName:Containers |
PowerShell script
1 |
disable-windowsoptionalfeature -online -featureName containers -NoRestart |