How do I convert a vhd to a wim file?
Solution 1
Absolutely, let's post a prim and proper answer for Google. This is a simple 2 command Powershell execution, using the dism
module. The dism can be copied to earlier versions of Windows, provided you have the appropriate version of the windows management framework.
First, mount the vhd using
Mount-WindowsImage -ImagePath C:\VHDs\BigHomies.vhdx -Path C:\VHDMount -Index 1
Then, capture it into a wim with
New-WindowsImage -CapturePath C:\VHDMount -Name Win7Image -ImagePath C:\CapturedWIMs\Win7.wim -Description "Yet another Windows 7 Image" -Verify
And let it do it's thing. When you are done you can unmount the vhd and discard any changes using:
Dismount-WindowsImage -Path C:\VHDMount -Discard
Solution 2
If, for some reason, Powershell is not an option - do not despair!
In Windows 7 or later, you can mount the .vhd via disk management (link)
Once it is mounted, you can use imagex.exe to capture the .wim (technet link)
Related videos on Youtube
MDMoore313
Professional software engineer that also enjoys IT work and the occasional widget invention. https://www.linkedin.com/in/mdmoore313/
Updated on September 18, 2022Comments
-
MDMoore313 over 1 year
I just setup and sysprepped a nice new VM, now I need to convert it to a wim real quick, to upload to my sccm server. For some reason, I can't change the VM properties to boot from a legacy nic for pxe, which is how I usually capture my images using sccm. VMM just changes the settings right back, even though it says successful.
Anyway, the first page of google was terrible for this, w/ the exception of a 3rd party .ps1 script on MS's website, but I'm using 2012r2, I should be able to do this natively, right?
-
Zech Burrus over 9 yearsCorrection to the second command: -ImagePath should specify the full path to the WIM file (e.g. C:\CapturedWIMs\NewWinImage.wim), while -Name is the name of the image inside the WIM file (e.g. NewWinImage, but has no actual relation to the WIM file name). Executing the originally posted command results in "New-WindowsImage: Access is denied." (presumably because the command attempts to treat the C:\CapturedWIMs directory as a file).
-
MDMoore313 over 9 yearsInteresting analysis, technet's example also seems to agree with you. I'll update it, even though I ripped this straight from my powershell prompt lol.
-
Joshua McKinnon almost 9 years+1 this answer really helped me out!
-
aggieNick02 over 7 yearsBe sure to run the x64 version of powershell (if on x64 windows) and run with administrator privileges. Failing to do either of those will result in various errors. See serverfault.com/questions/700839/…
-
ClearBoth almost 7 yearsI got access denied, if anyone can help. I tried to mount with disk management as well. I am using 64 version and with administrator privileges, still the error comes from the second command.
-
MDMoore313 almost 7 years@ClearBoth on the
New-WindowsImage
command? I wonder if the vhdx is in use, or otherwise cannot be locked. -
Aviose over 5 yearsSo, if your VHD is separated into multiple partitions, how do you get those to implement properly within the WIM file?