Monday, October 5, 2009

Change Windows Features for Windows 7 / Windows Server 2008 from the command line

In case you want to add or remove feature in Windows 7 or Windows Server 2008 (R2) from the command line, the utility DISM.exe is all you need.

Normally it is used to service WIM images, but it can also execute on “Online” images which means the currently running Windows.

To get a list of features your Windows supports and there state (Enabled or disabled) simply type:

DISM.EXE /Online /Get-Features

To save the output to a file, simply use redirection:

DISM.EXE /Online /Get-Features >C:\Features.txt

To enable (install) a feature use the /Enable-Feature command :

DISM.EXE /online /Enable-Feature /FeatureName:MicrosoftWindowsPowerShellISE

To disable (uninstall) it, use the /Disable-Feature command:

DISM.EXE /online /Disable-Feature /FeatureName:MicrosoftWindowsPowerShellISE

You can enable or disable several features at once:

DISM.EXE /online /Enable-Feature /FeatureName:WindowsServerBackup /FeatureName:WindowsServerBackupCommandlet

However, depending on which feature you change it can happen that one feature requires another so you usually end up having several DISM calls.

In case you want to automate the process fully, add the “/Quiet” parameter but remember that this will restart your computer without any question when necessary:

DISM.EXE /online /Quiet /Enable-Feature /FeatureName:WindowsServerBackup /FeatureName:WindowsServerBackupCommandlet

Sometimes the names in the output of DISM are different from what you see inside the “Turn Windows feature on or off” (Windows 7) or “Add/Remove features” (Server 2008). For example, the IIS feature “Logging Tools” is called “IIS-LoggingLibraries” when using DISM.

To find out how the feature you are searching for is named, simply export the current list of features with this command:

DISM.EXE /Online /Get-Features >C:\Features_Before.txt

Then turn the feature on manually and once the installation is completed, use the following command:

DISM.EXE /Online /Get-Features >C:\Features_After.txt

A simply text compare on these two files will then show which feature has changed its state from “Disabled” to “Enabled”.

No comments:

Post a Comment