Getting Started with DISM PowerShell Cmdlets

Last Update: Sep 04, 2024 | Published: Jun 03, 2015

PowerShell

SHARE ARTICLE

For a while now IT pros have used the DISM command to manage Windows images and installations, which isn’t an especially difficult tool to use. Because it is a command line tool, everything it outputs is text, and this can make it tricky if you are trying to do anything with it. Fortunately, Windows 8 brought us a new module, conveniently called DISM. Let me introduce you to it and use some of the commands to adjust my desktop settings.

DISM isn’t required anymore because PowerShell automatically imports modules when you use one of its commands. But you probably don’t know what those commands are called, so we’ll go ahead and explicitly import the module.

import-module dism

What can the module do for us?

get-command -Module DISM

Looks like quite a lot.

DISM PowerShell cmdlets. (Image Credit: Jeff Hicks)
DISM PowerShell cmdlets. (Image Credit: Jeff Hicks)

Perhaps we should organize the results into something easier to read.

get-command -Module DISM | sort Noun,Verb | format-table -GroupBy Noun
DISM PowerShell cmdlets. (Image Credit: Jeff Hicks)
DISM PowerShell cmdlets. (Image Credit: Jeff Hicks)

All of these commands should have full help, which I’ll leave to you to read. Don’t forget you can also get online help as well.

help Get-WindowsEdition –online

Let’s try this one.

Get-windowsedition –online
The get-windowsedition cmdlet. (Image Credit: Jeff Hicks)
The get-windowsedition cmdlet. (Image Credit: Jeff Hicks)

I don’t have a need to change my current edition, so let’s look at optional features. You can manually set them via the Control Panel under Programs.

Programs and features dialog. (Image Credit: Jeff Hicks)
Programs and features dialog. (Image Credit: Jeff Hicks)

This leads you to different options for turning Windows features on or off.

Turn Windows features on or off. (Image Credit: Jeff Hicks)
Turn Windows features on or off. (Image Credit: Jeff Hicks)

Instead, let’s use PowerShell and some of the DISM cmdlets. I know from looking at commands earlier that there is something that’s a good candidate. After reading help, I give it a try.

Get-WindowsOptionalFeature –Online
The get-windowsoptionalfeature cmdlet in Windows PowerShell. (Image Credit: Jeff Hicks)
The get-windowsoptionalfeature cmdlet in Windows PowerShell. (Image Credit: Jeff Hicks)

Now that I see what the output is like, you can also re-run the command and pipe to Get-Member to discover property names. Now, I can easily find optional features I haven’t installed yet.

The get-windowsoptionalfeature cmdlet in Windows PowerShell. (Image Credit: Jeff Hicks)
The get-windowsoptionalfeature cmdlet in Windows PowerShell. (Image Credit: Jeff Hicks)

In the list is the Telnet client, which could come in handy as a troubleshooting tool.

Get-WindowsOptionalFeature -FeatureName TelnetClient –Online
The Telnet Client allows you to connect to other computers remotely. (Image Credit: Jeff Hicks)
The Telnet Client allows you to connect to other computers remotely. (Image Credit: Jeff Hicks)

Looks good to me. I need to enable it. Looking back in the list of commands, I saw an Enable-WindowsOptionalFeature cmdlet. Again, after reading help this should enable the feature.

Enable-WindowsOptionalFeature -FeatureName TelnetClient –Online

This particular feature installs quickly and doesn’t require a reboot.

The Enable-WindowsOptionalFeature cmdlet. (Image Credit: Jeff Hicks)
The Enable-WindowsOptionalFeature cmdlet. (Image Credit: Jeff Hicks)

And sure enough it is now installed.

The Telnet client has successfully installed. (Image Credit: Jeff Hicks)
The Telnet client has successfully installed. (Image Credit: Jeff Hicks)

While I’m at it, let me check the status of the optional Windows PowerShell 2.0 feature. I’m not sure what the feature is called, but fortunately I can use wildcards.

get-windowsoptionalfeature -FeatureName *PowerShell* -Online

Scrolling down I see the features.
041015 1702 GettingStar11
I want to remove the highlighted features. Let’s refine my wildcard pattern and disable the matching features.

Get-WindowsOptionalFeature -FeatureName MicrosoftWindowsPowerShellV2* -Online | Disable-WindowsOptionalFeature –Online
Disabling matching features. (Image Credit: Jeff Hicks)
Disabling matching features. (Image Credit: Jeff Hicks)

Done! I can even verify by trying to start a v2 session.
041015 1702 GettingStar13
Mission accomplished! Should I find the need to re-enable it, I can re-run the previous command and use Enable-WindowsOptionalFeature. All of this is so much faster than navigating through the GUI under Control Panel.

There are a few caveats. The Enable and Disable cmdlets don’t support –WhatIf or –Confirm, although I wish they would. Technically, I believe they should support these parameters because you are changing the state of the system. That is why it is very important to read cmdlet help. And if you intend to try out the DSM cmdlets, I strongly encourage you to use a test computer, preferably virtualized so that you can easily rollback changes, should things get out of hand.

SHARE ARTICLE