Home » PowerShell » Disable Windows Optional Features using PowerShell

Disable Windows Optional Features using PowerShell

Use the Disable-WindowsOptionalFeature cmdlet in PowerShell to disable or removes an optional feature in a Windows image. You can use the Online parameter to specify the running operating system on your local computer or use the Path parameter to specify the location of a mounted Windows image.

The Disable-WindowsOptionalFeature disable an optional feature in the running operating system, use the Remove parameter to remove the files for an optional feature without removing the feature’s manifest from the image.

The Disable-WindowsOptionalFeature syntax contains parameters that can be used to specify feature name, package name, online, package path, path, windows directory, Remove, and log level.

In this article, we will discuss how to use the Disable-WindowsOptionalFeature cmdlet in PowerShell to disable or remove optional features such as hyper-v, netfx3, .net3.5, rsat and many others on the running Windows operating system.

Cool Tip: The Disable-WindowsOptionalFeature requires elevation. You must open the PowerShell terminal as “Run as administrator” to run the cmdlet.

What is the Syntax of Disable-WindowsOptionalFeature

The syntax of Disable-WindowsOptionalFeature is given below.

Disable-WindowsOptionalFeature
       -FeatureName <String[]>
       [-PackageName <String>]
       [-Remove]
       [-NoRestart]
       [-Online]

       -Path <String>
       [-WindowsDirectory <String>]
       [-SystemDrive <String>]
       [-LogPath <String>]
       [-ScratchDirectory <String>]
       [-LogLevel <LogLevel>]
       [<CommonParameters>]

Parameters used in the Disable-WindowsOptionalFeature are given below.

-FeatureName: The name of a feature to be disabled. Feature names are case-sensitive.

-PackageName: The name of the package as it is listed in the Windows image.

-Path: It specifies the full path to the root directory of the offline Windows image that you will service.

-Online: Use the Online parameter to specify the running operating system on your local computer.

-Remove: It removes the files for an optional feature without removing the feature’s manifest from the image.

-LogPath: It specifies the full path and file name to log to. If not set, then it uses the default path as %WINDIR%\Logs\Dism\dism.log.

-ScratchDirectory: It specifies the temporary directory that will be used while extracting files for use during servicing. The directory must exist locally. If it is not specified, it will use %Windows\%Temp%.

Let’s understand the PowerShell Disable-WindowsOptionalFeature cmdlet in the DISM module with examples. In the below examples, we will use the command to disable optional features in the running Windows operating system, on the mounted image.

How to Disable an Optional Feature

Use the Disable-WindowsOptionalFeature cmdlet in PowerShell to disable or remove an optional feature.

Disable-WindowsOptionalFeature -Online -FeatureName "Hearts"

In the above PowerShell script, the Disable-WindowsOptionalFeature command disables an optional feature, Hearts, from the Windows operating system.

Cool Tip: How to get Windows optional features using PowerShell!

How to Disable Hyper-V feature on Windows OS

To disable the hyper-v feature on the Windows operating system, use the Disable-WindowsOptionalFeature command and specify the “Microsoft-Hyper-V-All” feature name.

Disable-WindowsOptionalFeature -Online -FeatureName  "Microsoft-Hyper-V-All"  

In the above PowerShell script, the Disable-WIndowsOptionalFeature command disables Hyper-V on the Windows operating system. A restart of the computer is needed to complete this operation.

The output of the above script after disabling the hyper-v on Windows OS is:

PS C:\> Disable-WindowsOptionalFeature -Online -FeatureName  "Microsoft-Hyper-V-All"                                    

Do you want to restart the computer to complete this operation now?
[Y] Yes  [N] No  [?] Help (default is "Y"): n


Path          :
Online        : True
RestartNeeded : True



PS C:\> 

Cool Tip: How to enable Windows optional feature using PowerShell!

Conclusion

I hope the above article on how to disable Windows optional features using the Disable-WindowsOptionalFeature cmdlet in PowerShell is helpful to you.

We have learned how to use the cmdlet Disable-WindowsOptionalFeature in PowerShell to disable optional features, disable Hyper-V features in the running operating system, and a mounted image using different parameters.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.