Gert Lombard's Blog     About     Archive     Feed
My passion is code quality, automated testing, software craftsmanship.

Enabling and disabling Windows Features from the command line

This blog post briefly describes how to use the DISM.EXE command to enable or disable Windows Features from the command line. Normally you’d use the Programs and Features –> Turn Windows features on or off dialog in the Control Panel to enable a Windows feature such as IIS or MSMQ. I prefer to use the command line for anything I can, partly because of a left-over habit from my DOS (and some Linux) days, but mostly because it means I can automate things in batch files.

Start an elevated command prompt. (Right-click on Command Prompt and click "Run as administrator").

To find the name of the feature you want to enable or disable, first list all the installed features. To list all the features available on the PC, whether enabled or not, run:

C:\> dism /Online /Get-Features

This will display the long list of all the available features and their Enabled/Disabled state.

Filter to the list to find the name of the specific feature you're looking for.  For example, to find the Hyper-V features:

C:\> dism /Online /Get-Features /Format:Table | find "Hyper"
Microsoft-Hyper-V-All                                 | Disabled
Microsoft-Hyper-V-Tools-All                           | Disabled
Microsoft-Hyper-V                                     | Disabled
Microsoft-Hyper-V-Management-Clients                  | Disabled
Microsoft-Hyper-V-Management-PowerShell               | Disabled

When you find the name of the feature (for example Microsoft-Hyper-V), you can enable it with:

C:\> dism /Online /Enable-Feature /FeatureName:Microsoft-Hyper-V /All

Deployment Image Servicing and Management tool
Version: 6.2.9200.16384

Image Version: 6.2.9200.16384

Enabling feature(s)
[==========================100.0%==========================]
The operation completed successfully.
Restart Windows to complete this operation.
Do you want to restart the computer now? (Y/N)

Similarly, to disable the feature again, run:

C:\> dism /Online /Disable-Feature /FeatureName:Microsoft-Hyper-V-All

Deployment Image Servicing and Management tool
Version: 6.2.9200.16384

Image Version: 6.2.9200.16384

Disabling feature(s)
[==========================100.0%==========================]
The operation completed successfully.
Restart Windows to complete this operation.
Do you want to restart the computer now? (Y/N)

This should work on Windows 8 as well as Windows 7 and Windows Server 2008 R2.