WIM or Windows Image is a file-based disk image format that was developed by Microsoft to deploy Windows. To understand this better, ISO or VHD are sector-based formats, while WIM is a file-based format for a disc. If you are implementing a large number of WIM files on multiple computers and some of them fail, here is how to dismount or bulk remove the failed WIMs.
The reason why WIM is useful is that, regardless of its hardware, you can make them bootable using WIMBoot. Since the Windows boot loader supports booting Windows from a WIM file, it becomes easier to deploy.
How to unmount or delete a failed WIM
There are three ways to dismount or bulk remove failed WIMs on a Windows system:
- PowerShell registry path method
- Using the Dismount-WindowsImage method
- Windows PowerShell 7 parallel method
You can use any of these methods, but the latter works only with PowerShell 7.
1]Powershell registry path method
Adam Gross, Microsoft MVP, published this method. You can use this method to find the location of all mounted images, extract the deletion state, and then unmount each one.
Get-ChildItem -Path "HKLM:SOFTWAREMicrosoftWIMMountMounted Images" | Get-ItemProperty | Select -ExpandProperty "Mount Path" | ForEach-Object {Dismount-WindowsImage -Path $_ -Discard}
However, this will loosen the failed WIMs one at a time in sequence and will take approximately 25 seconds each.
2]Dismount-WindowsImage method
It is a PowerShell command that can be used to delete or save changes to a Windows system image and then unmount it. So it’s not just chess, but it works for everyone too. The best part is that it can save the state if you plan to temporarily dismount a WIM.
To discard and disassemble
Dismount-WindowsImage -Path[-Discard] [-LogPath ] [-ScratchDirectory ] [-LogLevel ] [ ]
To save and dismount
Dismount-WindowsImage -Path[-Save] [-CheckIntegrity] [-Append] [-LogPath ] [-ScratchDirectory ] [-LogLevel ] [ ]
Sample order
Dismount-WindowsImage -Path "c:offline" -Discard
- Path: specifies the location of the mounted Windows system image.
- Add: Location of an existing .wim file to add the Windows image to when you unmount it instead of replacing the existing image.
- CheckIntegrity The parameter detects and tracks corruption of the .wim file.
So the final command will now look like (Thank you Manel) –
Get-WindowsImage -Mounted | ForEach {Measure-Command {Dismount-WindowsImage -Discard -Path $_.Path}}
3]Bulk unmounting eliminates failed WIMs using Windows PowerShell 7’s parallel method
It is available in preview and will be available with PowerShell 7. According to Merlin, this new method disassembled three images in just under 10 seconds instead of almost 25 seconds when executed in sequence.
Get-WindowsImage -Mounted | foreach -Parallel {Measure-Command {Dismount-WindowsImage -Discard -Path $_.Path}}
These are some of the best methods you can use to mass disassemble or eliminate failed WIMs in one go.
Disassembly doesn’t take much time, but it can be huge for enterprise deployment. The parallel switch is going to be a life saver for many because it is fifty percent faster compared to the sequential method.