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.

Disclaimer:

The sample scripts provided below are adapted from third-party open-source sites.

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

Batch script output listing all optional features

PowerShell script

PowerShell script output listing all optional features

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

Batch script output showing the detailed description of a feature

PowerShell script

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.

PowerShell script output showing the detailed description of a feature

Get a list of all enabled Windows optional features

The scripts provided below retrieve a list of all enabled Windows optional features.

Batch script

Batch script output listing all enabled features

PowerShell script

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.

PowerShell script output listing all enabled features

Get a list of all disabled Windows optional features

The scripts provided below retrieve a list of all disabled Windows optional features.

Batch script

Batch script output listing all disabled features

PowerShell script

PowerShell script output listing all disabled features

Enable a Windows optional feature

The scripts provided below are used to enable Windows optional features.

Batch script

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

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

PowerShell script

Notes:

  • When using Batch scripts, it’s important to note that the value associated with the FeatureName parameter is case-sensitive and space-sensitive.
  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository