Windows 7 DISM – how to mount, manage, and service WIM images

Michael PietroforteMVP By Michael Pietroforte - Tue, February 10, 2009 - 24 comments google+ icon

Michael Pietroforte is the founder and editor of 4sysops. He is a Microsoft Most Valuable Professional (MVP) with more than 30 years of experience in system administration.

In my last post, I wrote about DISM’s (Deployment Image Servicing and Management) Vista compatibility and its relation to imageX. Today I will post some examples that will show you how to mount a WIM image, how to gather information about an image, and how to service images with DISM.

Before you start working with an image, you might want to have some information about the image. The following command retrieves information about the OS images that are contained within a WIM file. As you probably know, a WIM image can contain multiple OS images.

dism-get-wiminfodism /Get-WimInfo /WimFile:d:\sources\install.wim

I used Windows 7 Beta’s WIM file, which you can find in the “sources” folders on the DVD. If you add the command line option /index plus the image’s index number, you will get information about a specific image such as the OS version, size, installed service pack, etc. (see screenshot).

dism-get-wiminfo-index dism /Get-WimInfo /WimFile:d:\sources\install.wim /index:4

Before you can work with a WIM image, you have to mount it to a folder. DSM’s syntax differs from that of imageX. Perhaps DSM’s is easier to read in scripts, but it also requires more typing work, than imageX’s:

dism /Mount-Wim /wimfile:c:\wim\install.wim /index:4 /MountDir:c:\img

Note that if you mount an image onto a DVD, you have to add “/ReadOnly” to the command. DISM parameters are not case sensitive, so you can spare a few keystrokes if you want. You have to replace “c:\wim\install.wim” with the location where you copied the WIM file, and “c:\img” with the folder in which you want to mount the WIM image. “/index:4″ specifies the fourth OS image within the WIM image, which is Windows 7 Ultimate in install.wim.

Once you have mounted an image, you can navigate through its folder structure using Windows Explorer, and make changes to all files and folders. In most cases, however, you will be using DISM to gather specific information about an image and also to add features, drivers, and packages.

dism-get-drivers The following example lists all installed third party drivers in the image I mounted to c:\img.

dism /image:c:\img /Get-Drivers

The DISM documentation describes commands that are used to retrieve information as “management tasks.” This is a bit odd because usually “management” also implies making changes to the managed object. Other examples of such management operations include Get-Features (Windows features), Get-Packages (feature packs, language packs, updates, etc.), and /Get-Intl (international settings and languages).

All commands that are related to changing an image are called “servicing tasks.” The next command is such a servicing task, which disables the Solitaire game in Windows 7.

dism /image:c:\img /Disable-Feature:Solitaire

Note that you have to know the exact name if you want to enable or disable Windows features. You can enumerate all Windows features with this command:

dism /image:c:\img /Get-Features | more

Because there are more features than would fit on the screen, you have to use the pipe plus “more”; this will display the features a page at a time.

Whenever you make several changes, you should save the image’s current state. This command will apply to all changes you make.

dism /Commit-Wim /MountDir:c:\img

You also can apply changes once you are finished and want to unmount the image.

dism /Unmount-Wim /MountDir:c:\img /commit

If you don’t want to apply the changes, you can use the /discard parameter instead of /commit.

dism-online-get-packages DISM has an interesting feature that I mentioned in my introduction. It allows you not only to manage offline images, but also to work with the currently running operating system.

dism /online /Get-Packages

This command lists all packages installed on your Windows computer. Essentially, the /online option works like the /image parameter, but manages or services an “online image,” and not an offline image.

DISM certainly is a powerful tool. In this article, I have only scratched the surface. You can find all of DISM’s command line options in the WAIK (Windows Automated Installation Kit) documentation.

I have only one complaint about DISM. Some days ago, I attended a Microsoft online meeting that introduced DISM. One of the participants asked why there is no GUI version of DISM. A Microsoft developer answered that a command line tool can be used in scripts to automate tasks on multiple images. Well, this is the standard excuse for delivering command line tools. Of course, it is also possible to automate all kinds of tasks with a well-programmed GUI tool. The point is that the development of a GUI tool is more costly than a command line utility. The good news is that the developer also said that Microsoft is planning to release a GUI version of DISM in the future.

-1+1 - Rate this post
Loading ... Loading ...
Disclaimer
Your question wasn't answered? Please ask in the new 4sysops forum!

24 Comments- Leave a Reply

  1. tommy says:

    some what the same tool as “GImagex” here is another tool for not only managing (mount, edit, create) WIM images but ISO and VHD’s as well…its free at the moment. Thought I would share..

    http://www.portlock.com/products/license_manager/

  2. Lowlyduane says:

    can you install microsoft updates and/or new programs on a mounted .wim file?

  3. Mark Eddy says:

    I understand that you can mount a windows 7 .wim image file and update files, etc. This mounting process sounds like the only thing I’ll see are the files from the image. As you know Microsoft is always coming up with updates that you can install from the update.microsoft website. Does this mounting process allow me to do updates from the website and if not, how would I?

  4. Johny says:

    @Mark

    I just spent literally hours trying to figure this out. No clue why I couldn’t find a straight forward answer anywhere. But here it is: You can install updates, not from the update website though. You have to download the actual .cab file for each patch, and from there you can use the /Add-Package parameter to specify the update. I used http://www.wsusoffline.net/ to download the patches, then I wrote a script to mount the image, apply the packages, and unmount for me.

  5. Ba says:

    @Johny

    Can you please share the script you wrote with us?
    Thanks in advance

  6. Johny says:

    It’s a powershell script. I haven’t fully implemented this yet. Sort of fell on the priority list. My idea is to eventually get the offline updates to download automatically once a week, maybe through task scheduler, and then have this script run afterwards to automatically apply the updates to the image. For now, it at least saves some time on typing commands.
    ______________________________
    #Mount directory for WIM file
    $mountdir = “C:\servicing”

    #Directory where the update packages are located
    $updatedir = “C:\offlineupdates”

    #Location of DISM
    $dism = “C:\Program Files\Windows AIK\Tools\Servicing\dism.exe”

    #WIM file to mount
    $wimfile = “C:\Windows7_base.wim”

    #Image index of WIM file
    $wimindex = “1″

    #Array to hold the package locations
    $packagepath = @()

    #Command to mount the WIM
    invoke-expression “& ‘$dism’ /mount-wim /wimfile:$wimfile /index:$wimindex /mountdir:$mountdir”

    #Add every .cab file to the $packagepath array
    $updatepackages = get-childitem $updatedir | where{$_.extension -eq “.cab”}
    For ($i=0; $i -le $updatepackages.Count – 1; $i++)
    {
    $package = $updatepackages[$i].name
    $packagepath += “/PackagePath:$updatedir\$package”
    }

    #Add packages to the WIM
    invoke-expression “& ‘$dism’ /image:$offlineimage /Add-Package $packagepath”

    #Unmount WIM
    invoke-expression “& ‘$dism’ /unmount-wim /mountdir:$mountdir /commit”
    __________________________________________

  7. Excellent timing!! I started doing some research on how to do this yesterday (27th may), and I am no scripter at all.
    Thank you for this powershell script, I am going to try this and will let all of you know about the results!

  8. What a shame, I;ve tried the script, but get the following error message:
    Unexpected token ‘&’ in expression or statement.
    At C:\Users\borg_adm\Desktop\updateImage.ps1:20 char:21
    + invoke-expression “& <<<< '$dism' /mount-wim /wimfile:$wimfile /index:$wimindex /mountdir:$mountdir"
    + CategoryInfo : ParserError: (&:String) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken

    Like I said, I'm no scripter at all, what can I do about this?

  9. Never mind, made a copy-error….
    #Image index of WIM file
    $wimindex = “1?

    In stead of:
    #Image index of WIM file
    $wimindex = “1″

  10. Another error now…
    Error: 87

    The /image: option is missing a required argument.
    For more information, refer to the help for the /image: option.

    I think this happens when the following command is run:
    invoke-expression “& ‘$dism’ /image:$offlineimage /Add-Package $packagepath”

    It seems the variable $offlineimage is not set (since I can’t find this variable anywhere else in the script).
    I already tried the following command:
    invoke-expression “& ‘$dism’ /image:$mountdir /Add-Package $packagepath”
    But then it says the following:
    Error: 2

    Unable to access the image.
    Make sure that the image path and the Windows directory for the image exist and you have Read permissions on the folder.

    When I manually provide the mount dir (eg: /image:e:\service in my case) I recieve the exact same error.

  11. The script seems to work fine when I replaced this line:
    #Add packages to the WIM
    invoke-expression “& ‘$dism’ /image:$offlineimage /Add-package $packagepath”

    By this line:
    #Add packages to the WIM
    invoke-expression “& ‘$dism’ /image:’$mountdir’ /Add-package $packagepath”

  12. Johny says:

    You’re right! Sorry about that, I had went back through and changed the variable names so that they made more sense and apparently I missed that one :)

    And you say you’re not a scripter…

  13. Alberto says:

    Do you guys know if the user account information can be modified on a WIM file. For example: the password, or create a new account?

    Thanks.

  14. Kyle says:

    I have used wsusoffline to download the windows 7 and office 2007 updates, however all of the office updates are .exe. Is there any way to get the office updates applied using your script? Am I just looking in the wrong update download folder that wsusoffline creates?

    Any help is much appreciated.

  15. Johny says:

    I don’t believe there is anyway to use the .exe on the wim file. However, you might consider installing office 2007 post-image and use the instructions from microsoft below to utilize the .exe update files.

    http://technet.microsoft.com/en-us/library/cc178995(office.12).aspx#DeployInitialUpdViaUpdatesFolder

  16. ELDI says:

    I make this small program in java for use the Dism.exe present in Windows 7 with GUI or Visual Mode,

    Download Link:
    GDism ELDI v2.2 Final:
    http://www.mediafire.com/?uvxd4dk6kuv9ian
    Commands you can use on GUI or Visual Mode:
    * Mount-Wim
    * Commit-Wim
    * Unmount-Wim
    * Get-WinInfo
    * Get-MountedWinInfo
    * CleanUp-Wim
    * Get-Packages
    * Add-Package
    * Remove-Package
    * Get-Drivers
    * Get-DriverInfo
    * Add-Driver
    * Remove-Driver
    * Make ISO
    You must need the JRE installed (Java Runtime Enviroment).

    @ByELDI

    v2.2
    Progress Bar
    Time Counter

    v2.1
    Fixed iso making
    Menu translated
    Button Cancel Process

    v2.0
    Better Interface for results text
    Make iso image with oscdimg
    Support WAIK
    Support x64
    Better Config File
    Size reduced

    v1.4
    Fixed Process on wait list
    Config File

    v1.3
    Translate English-Espanol
    Multiples Process Waiting

    v1.2
    Fixed Drivers Functions

    http://www.mediafire.com/?uvxd4dk6kuv9ian

  17. Chris V says:

    Excellent post, best way I have seen it explained. thanks a million.

  18. Mark Dart says:

    HI I was after some clear instruction on how to capture my SOE image into a .wim file. I have been doing OS deployment and then applying the software packages through enteo. They want me to speed up this process by giving Dell an image of our soe. Dell came back with they will except a *.wim file. So I have just started researching using WAIK to capture a image and I am just getting lost with the information I am reading.

  19. Mike says:

    I created a very simple GUI interface for DISM based on .NET. It doesn’t have all the DISM features implemented yet but I plan on adding more soon. Take a look.

    http://mikecel79.wordpress.com/2010/12/22/dism-gui-2-0/

  20. Big Al says:

    Fantastic post and a life saver. Used this to extract drivers from a Vista Image to use on a downgrade to Windows XP.

  21. czteck says:

    My question is about using dism /add package to an index of an image. Do I have to apply the updates to all the indexes in the image, or can I do it one and have it applied to all the indexes?

  22. acsheehy says:

    czteck, I think you will find the answer to be yes/no. To be sure, mount the image and to a DISM /image:c:\mount_point /get-packages >featurelist.txt after you have updated the first image.

    I think you will find they have not been applied to the second. So Yes, you have to apply the update to all the index, and no you cannot apply it to one and expect the other image to be updated.

  23. bharath says:

    Hi all,
    I’m new to DISM.
    Can we update the windows server 2008 r2 VM offline which is in .vmdk format ?

    please reply as soon as possible.

    thank you.

Please share your thoughts in a comment!

Login

Lost your password?