WIM or Windows Image is a file-based disk image format that was developed by Microsoft to deploy Windows. To understand it better, ISO or VHD are sector-based formats, while WIM is a file-based format for a disk. If you are implementing a lot of WIM files on multiple computers, and some of them fail, here is how to bulk dismount or discard failed WIMs.
WIM is useful because it is hardware-independent. You can make it bootable using WIMBoot. Since the Windows bootloader supports booting Windows from within a WIM file, it becomes easier to deploy.
How to Unmount or Discard a failed WIM
There are three ways to dismount or discard failed WIMs in bulk on a Windows system:
- PowerShell Registry path method
- Using Dismount-WindowsImage method
- Windows PowerShell Parallel method
You can use any of these methods, but the last one works with PowerShell 7 only.
1] Powershell Registry path method
Adam Gross, a Microsoft MVP, posted this method. You can use this method to find the location of all mounted images, extract the discard status, and then dismount each of them.
Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\WIMMount\Mounted Images" | Get-ItemProperty | Select -ExpandProperty "Mount Path" | ForEach-Object {Dismount-WindowsImage -Path $_ -Discard}
However, this will bulk dismount discard failed WIMs one by one in sequence and takes around 25 seconds each.
2] Dismount-WindowsImage method
It is a PowerShell command that can be used to discard or save changes to a Windows image and then dismount it. So it’s not just for failed ones but also works for all. The best part is that it can save the state if you are planning to unmount a WIM temporarily.
To Discard and dismount
Dismount-WindowsImage -Path <String> [-Discard] [-LogPath <String>] [-ScratchDirectory <String>] [-LogLevel <LogLevel>] [<CommonParameters>]
To Save and Dismount
Dismount-WindowsImage -Path <String> [-Save] [-CheckIntegrity] [-Append] [-LogPath <String>] [-ScratchDirectory <String>] [-LogLevel <LogLevel>] [<CommonParameters>]
Sample Command
Dismount-WindowsImage -Path "c:\offline" -Discard
- Path: specifies the location of the mounted Windows image.
- Append: Location of an existing .wim file to add the Windows image to when you dismount it instead of overwriting the existing image.
- CheckIntegrity parameter detects and tracks .wim file corruption.
So the final command will now look like (Thanks Manel) –
Get-WindowsImage -Mounted | ForEach {Measure-Command {Dismount-WindowsImage -Discard -Path $_.Path}}
3] Bulk dismount discard failed WIMs using Windows PowerShell Parallel method
It is available in preview and will be available with PowerShell 7. According to Merlin, this new method dismounted three images in just under 10 seconds instead of almost 25 seconds when ran in sequence.
Get-WindowsImage -Mounted | foreach -Parallel {Measure-Command {Dismount-WindowsImage -Discard -Path $_.Path}}
These are some of the best methods for dismounting or discarding failed WIMs in bulk.
While unmounting one doesn’t take much time, this can be huge for Enterprise deployment. The parallel switch will be a life savior for many, as it is fifty percent faster than the sequential method.