For a while now IT pros have used the command-line tool DISM.EXE 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.
What can the module do for us?
get-command -Module DISM
Looks like quite a lot.
Perhaps we should organize the results into something easier to read.
get-command -Module DISM | sort Noun,Verb | format-table -GroupBy Noun
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.
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.
This leads you to different options for turning Windows features on or off.
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.
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.
In the list is the Telnet client, which could come in handy as a troubleshooting tool.
Get-WindowsOptionalFeature -FeatureName TelnetClient –Online
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.
And sure enough it is now installed.
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.
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
Done! I can even verify by trying to start a v2 session.
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.