22

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?

MDMoore313
  • 5,531
  • 6
  • 34
  • 73

3 Answers3

30

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
Greg Bray
  • 5,530
  • 5
  • 33
  • 52
MDMoore313
  • 5,531
  • 6
  • 34
  • 73
  • 1
    Correction 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). – Jakub Berezanski Oct 01 '14 at 22:34
  • Interesting analysis, [technet's example](http://technet.microsoft.com/en-us/library/dn376479.aspx) also seems to agree with you. I'll update it, even though I ripped this *straight* from my powershell prompt lol. – MDMoore313 Oct 03 '14 at 12:20
  • 1
    +1 this answer really helped me out! – Joshua McKinnon Jul 20 '15 at 17:45
  • Be 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 http://serverfault.com/questions/700839/new-windowsimage-stalls-with-0x8007007e-cant-load-unattend-dll/807578#807578 – aggieNick02 Oct 12 '16 at 19:37
  • I 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. – ClearBoth Jun 01 '17 at 10:28
  • 1
    @ClearBoth on the `New-WindowsImage` command? I wonder if the vhdx is in use, or otherwise cannot be locked. – MDMoore313 Jun 05 '17 at 15:43
  • So, if your VHD is separated into multiple partitions, how do you get those to implement properly within the WIM file? – Aviose Sep 12 '18 at 21:18
3

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)

Vlad274
  • 131
  • 3
0

Same method as the accepted answer, but without the need for PowerShell

dism /Mount-Image /ImageFile:C:\Backup.vhdx /Index:1 /MountDir:C:\Mount
dism /Capture-Image /ImageFile:C:\Backup.wim /CaptureDir:C:\Mount /Name:Backup
Dism /Unmount-Image /MountDir:C:\Mount /Discard
fjch1997
  • 101
  • 2