Controlling Windows Features from Command Line with DISM on Windows 7, 8, 10, and Server

The Deployment Image Servicing and Management tool (DISM) is perfect for IT professionals and power users that want to manage Windows components without using the GUI.

DISM mounts an online Windows image (.wim) file or virtual hard disk (.vhd or .vhdx) for servicing. You can also use DISM to install, uninstall, configure, and update the features and packages in offline Windows images and offline Windows Preinstallation Environment (WinPE) images. Since it is a command line utility it can be used in scripts to manage components.

Using DISM requires an administrative level command prompt. Click on the Start Button, type in cmd, hold down Shift and Ctrl and hit Enter (holding down Shift and Ctrl while hitting enter will start any command you type in as administrator).

Getting help, information and list of options

dism /?
dism /Get-Help
dism /online /?
dism /image:D:\test\offline /?

Get capabilities in the image
dism /online /Get-Capabilities
dism /image:D:\test\image.wim /Get-Capabilities

List all of the features available in the operating system
dism /online /get-features | more and hit Enter.

There’s an example of that list at the bottom of this article (from Windows 7).

To mount an offline image, type:
dism /Mount-Image /ImageFile:D:\test\image /Name:"Windows Image" /MountDir:C:\test\dir

To edit an offline image, specify the location of the mounted image directory, type:
dism /Image:D:\test\image /Get-Features

We can pipe it to more or use >image-featurelist.txt to redirect the output of the command to a text file that is named image-featurelist.txt. Example:
dism /online /get-features > C:\dir\image-featurelist.txt
dism /Image:D:\test\offline.image /Get-Features > C:\dir\image-featurelist.txt

For info about the specific feature we are interested in, say TFTP, type:
dism /online /Get-FeatureInfo /FeatureName:TFTP

Enable Windows features

We can use the /All argument to enable all of the parent features in the same command. For example, type:
dism /online /enable-feature /featurename:TFTP /All
Same with offline:
dism /Image:D:\test\image /Enable-Feature /FeatureName:TFTP /All

For status of that feature, type:
dism /online /Get-FeatureInfo /FeatureName:TFTP
dism /Image:D:\test\image /Get-FeatureInfo /FeatureName:TFTP

Restore removed Windows features

If we do not specify a source, DISM will look in the default location specified by group policy for the required files needed to enable the feature For more information, see Configure a Windows Repair Source.

If the files are not found in the default location, DISM will contact Windows Update (WU) for the required files. We can use the /LimitAccess argument to prevent DISM from contacting WU.
If we specify multiple /Source arguments, the files are gathered from the first location where they are found and the rest of the locations are ignored.
For example, type:
dism /Online /Enable-Feature /FeatureName:TFTP /Source:Z:\sources\SxS /Source:C:\test\mount\windows /LimitAccess

For offline, type:
dism /Image:D:\test\image /Enable-Feature /FeatureName:TFTP /Source:C:\test\mount\windows

Disable Windows features

Disable a specific feature in the image, type:
dism /online /Disable-Feature /FeatureName:TFTP

Offline image, type:
dism /Image:D:\test\image /Disable-Feature /FeatureName:TFTP

Remove Windows features for on-demand installation

dism /online /Disable-Feature /FeatureName:TFTP /Remove
dism /Image:D:\test\image /Disable-Feature /FeatureName:TFTP /Remove

The status here is Disabled. Beginning with Windows 10, the payload is not removed from Windows client SKUs in order to support push-button reset. The payload is removed from Windows Server SKUs.

Enable or disable Windows features by using DISM and an answer file

1. In Windows SIM, open an existing catalog by clicking Select a Windows Image on the File menu and specifying the catalog file type (.clg) in the drop-down list, or create a new catalog by clicking Create Catalog on the Tools menu.
2. Expand the catalog in the Windows Image pane, and then expand Packages.
3. Expand Foundation, and right-click Microsoft-Windows-Foundation-Package.
4. Click Add to Answer File.
5. Click Enabled or Disabled next to the features that you intend to enable or disable. Click the arrow to select the opposite choice.
We might have to expand an item to see all its children. We must enable the parent if any one of its children are enabled.
Note: You can’t restore or remove a Windows feature for features on demand with an unattended answer file.
6. Click Tools on the main menu, and then click Validate Answer File.
7. Correct any errors that appear in the Messages pane, and save the answer file.
8. At the command prompt, type the following command to apply the unattended answer file to the image.
dism /online /Apply-Unattend:C:\test\answerfiles\myunattend.xml
For offline, type:
dism /Image:D:\test\image /Apply-Unattend:C:\test\answerfiles\myunattend.xml

Commit changes on an offline image

dism /Unmount-Image /MountDir:D:\test\image /Commit

Let’s recap the most important options here

To list features: dism /online /get-features
To get status: dism /online /get-featureInfo /featurename:TFTP
To enable: dism /online /enable-feature /featurename:TFTP
To disable: dism /online /disable-feature /featurename:TFTP

Offline:
dism /ImageFile:D:\test\image /get-features
dism /Image:D:\test\image /Get-FeatureInfo /FeatureName:TFTP

Service names need to be entered exactly as listed, and remember to always reboot. If the dism command is used within a script and want to prevent asking to reboot simply append /NoRestart to the end of the command. If the status is Disable/EnablePending, the image/system needs to be rebooted.

The output of /get-features will be similar to this (output is from Windows 7):

Feature Name : OEMHelpCustomization
State : Disabled

Feature Name : CorporationHelpCustomization
State : Disabled

Feature Name : SimpleTCP
State : Disabled

Feature Name : SNMP
State : Disabled

Feature Name : WMISnmpProvider
State : Disabled

Feature Name : TelnetServer
State : Disabled

Feature Name : TelnetClient
State : Disabled

Feature Name : WindowsGadgetPlatform
State : Enabled

Feature Name : InboxGames
State : Disabled

Feature Name : More Games
State : Disabled

Feature Name : Solitaire
State : Disabled

Feature Name : SpiderSolitaire
State : Disabled

Feature Name : Hearts
State : Disabled

Feature Name : FreeCell
State : Disabled

Feature Name : Minesweeper
State : Disabled

Feature Name : PurblePlace
State : Disabled

Feature Name : Chess
State : Disabled

Feature Name : Shanghai
State : Disabled

Feature Name : Internet Games
State : Disabled

Feature Name : Internet Checkers
State : Disabled

Feature Name : Internet Backgammon
State : Disabled

Feature Name : Internet Spades
State : Disabled

Feature Name : IIS-WebServerRole
State : Disabled

Feature Name : IIS-WebServer
State : Disabled

Feature Name : IIS-CommonHttpFeatures
State : Disabled

Feature Name : IIS-HttpErrors
State : Disabled

Feature Name : IIS-HttpRedirect
State : Disabled

Feature Name : IIS-ApplicationDevelopment
State : Disabled

Feature Name : IIS-NetFxExtensibility
State : Disabled

Feature Name : IIS-HealthAndDiagnostics
State : Disabled

Feature Name : IIS-HttpLogging
State : Disabled

Feature Name : IIS-LoggingLibraries
State : Disabled

Feature Name : IIS-RequestMonitor
State : Disabled

Feature Name : IIS-HttpTracing
State : Disabled

Feature Name : IIS-Security
State : Disabled

Feature Name : IIS-URLAuthorization
State : Disabled

Feature Name : IIS-RequestFiltering
State : Disabled

Feature Name : IIS-IPSecurity
State : Disabled

Feature Name : IIS-Performance
State : Disabled

Feature Name : IIS-HttpCompressionDynamic
State : Disabled

Feature Name : IIS-WebServerManagementTools
State : Disabled

Feature Name : IIS-ManagementScriptingTools
State : Disabled

Feature Name : IIS-IIS6ManagementCompatibility
State : Disabled

Feature Name : IIS-Metabase
State : Disabled

Feature Name : WAS-WindowsActivationService
State : Disabled

Feature Name : WAS-ProcessModel
State : Disabled

Feature Name : WAS-NetFxEnvironment
State : Disabled

Feature Name : WAS-ConfigurationAPI
State : Disabled

Feature Name : IIS-HostableWebCore
State : Disabled

Feature Name : IIS-StaticContent
State : Disabled

Feature Name : IIS-DefaultDocument
State : Disabled

Feature Name : IIS-DirectoryBrowsing
State : Disabled

Feature Name : IIS-WebDAV
State : Disabled

Feature Name : IIS-ASPNET
State : Disabled

Feature Name : IIS-ASP
State : Disabled

Feature Name : IIS-CGI
State : Disabled

Feature Name : IIS-ISAPIExtensions
State : Disabled

Feature Name : IIS-ISAPIFilter
State : Disabled

Feature Name : IIS-ServerSideIncludes
State : Disabled

Feature Name : IIS-CustomLogging
State : Disabled

Feature Name : IIS-BasicAuthentication
State : Disabled

Feature Name : IIS-HttpCompressionStatic
State : Disabled

Feature Name : IIS-ManagementConsole
State : Disabled

Feature Name : IIS-ManagementService
State : Disabled

Feature Name : IIS-WMICompatibility
State : Disabled

Feature Name : IIS-LegacyScripts
State : Disabled

Feature Name : IIS-LegacySnapIn
State : Disabled

Feature Name : IIS-FTPServer
State : Disabled

Feature Name : IIS-FTPSvc
State : Disabled

Feature Name : IIS-FTPExtensibility
State : Disabled

Feature Name : IIS-WindowsAuthentication
State : Disabled

Feature Name : IIS-DigestAuthentication
State : Disabled

Feature Name : IIS-ClientCertificateMappingAuthentication
State : Disabled

Feature Name : IIS-IISCertificateMappingAuthentication
State : Disabled

Feature Name : IIS-ODBCLogging
State : Disabled

Feature Name : MediaPlayback
State : Enabled

Feature Name : WindowsMediaPlayer
State : Enabled

Feature Name : MediaCenter
State : Enabled

Feature Name : OpticalMediaDisc
State : Enabled

Feature Name : NetFx3
State : Enabled

Feature Name : WCF-HTTP-Activation
State : Disabled

Feature Name : WCF-NonHTTP-Activation
State : Disabled

Feature Name : RasRip
State : Disabled

Feature Name : RasCMAK
State : Disabled

Feature Name : MSMQ-Container
State : Disabled

Feature Name : MSMQ-Server
State : Disabled

Feature Name : MSMQ-Triggers
State : Disabled

Feature Name : MSMQ-ADIntegration
State : Disabled

Feature Name : MSMQ-HTTP
State : Disabled

Feature Name : MSMQ-Multicast
State : Disabled

Feature Name : MSMQ-DCOMProxy
State : Disabled

Feature Name : TabletPCOC
State : Enabled

Feature Name : ServicesForNFS-ClientOnly
State : Disabled

Feature Name : ClientForNFS-Infrastructure
State : Disabled

Feature Name : NFS-Administration
State : Disabled

Feature Name : SUA
State : Disabled

Feature Name : Printing-Foundation-Features
State : Enabled

Feature Name : Printing-Foundation-LPRPortMonitor
State : Disabled

Feature Name : Printing-Foundation-LPDPrintService
State : Disabled

Feature Name : Printing-Foundation-InternetPrinting-Client
State : Enabled

Feature Name : FaxServicesClientPackage
State : Enabled

Feature Name : ScanManagementConsole
State : Disabled

Feature Name : Xps-Foundation-Xps-Viewer
State : Enabled

Feature Name : TFTP
State : Disabled

Feature Name : MSRDC-Infrastructure
State : Enabled

Feature Name : Printing-XPSServices-Features
State : Enabled

Feature Name : Indexing-Service-Package
State : Disabled

Feature Name : Internet-Explorer-Optional-x86
State : Enabled

Feature Name : TIFFIFilter
State : Disabled

Feature Name : SearchEngine-Client-Package
State : Enabled

Sources
MSDN
MS Technet