Convert-WindowsImage.ps1 — WIM2VHD for Windows 10 (also Windows 8 and 8.1)

Convert-WindowsImage is the new version of WIM2VHD designed specifically for Windows 8 and above. Written in PowerShell, this command-line tool allows you to rapidly create sysprepped VHDX and VHDX images from setup media for Windows 7/Server 2008 R2, Windows 8/8.1/Server 2012/R2

4.6 Star
142,264 times
Add to favorites
E-mail Twitter Digg Facebook
  • 'Boot Failure' when creating an image with Win10 Pro
    1 Posts | Last post September 08, 2015
    • I've encountered some oddities with using the Convert-WindowsImage.ps1 script found on the Microsoft Script Gallery:
      Using my Win10 Enterprise desktop at home, I'm able to create bootable VHDX files from any OS and use them for VMs. If I run the exact same steps on my Surface 3 Pro (Win10 Pro), I am unable to create a bootable media.
      Edit: Followup from Twitter exchange.
      The error that occurs is when I try to start the VM with the created VHDX, the message is 'Boot failure.' This happens regardless of whether the image is Gen 1 (MBR) or Gen 2 (GPT). 
      Hyper-V: 10.0.10240.16431
      Powershell: 5.0.10240.16384
      Sample command:
      Convert-WindowsImage -SourcePath C:\VMs\ISOs\en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso -VHDPath C:\VMs\ISOs\GM2012R2Core.vhdx -VHDFormat VHDX -VHDType Dynamic -Edition ServerStandardCore -VHDPartitionStyle MBR -UnattendPath C:\VMs\ISOs\unattend.xml -BCDinVHD VirtualMachine 
      I can only speculate that there's a difference between Pro and Enterprise, but at this point I'm grasping at straws. I'm wondering if anyone else has run in to this.
      Cross-posted from:
  • Converting Win10 .wim to .vhdx fails with as others have reported
    6 Posts | Last post September 04, 2015
    • I think I have traced it back to Line 4237 in the script. The $openImage variable seems to be empty, and thus when it tried to call the .Apply method, it's failing. here is the code line that is bombing out:
           Line 4237 - $openImage.Apply($drive)
      In debug mode, $openImage does not have that method during runtime
    • The problem is with the assigning of WimImage[1] to openImage. This is because of a failing conversion with [Int32]. Instead, at line 4090, change the script to:
                          $noEdition = [Int32]0
                          if ([Int32]::TryParse($Edition, [ref]$noEdition)) {
                              $openImage = $openWim[$noEdition]    
                          } else {
                              $openImage = $openWim[$Edition]
      From that point on, openImage will be correctly assigned ($openImage is not empty) and Apply can be called correctly.
    • Oh, and this is my command given. edition parameter and value IS IMPORTANT. No support for strings !!!: 
      PS> . .\Convert-WindowsImage.ps1
      PS> Convert-WindowsImage -Sourcepath .\NanoServer.wim -edition 1 -vhdpath . \NanoServer.vhdx -VHDFormat VHDX -VHDPartitionStyle GPT
      PS> exit
    • This doesn't really fix the problem. The following line will result in the same image as your fix and your command line:
      PS> Convert-WindowsImage -sourcepath .\NanoServer.wim -Edition "CORESYSTEMSERVER_INST
      ALL" -VHDPath .\nanoserver.vhdx -VHDFormat vhdx -VHDPartitionStyle gpt
      The problem is the script is not parsing the Editions. To verify run this command:
      PS> Convert-WindowsImage -sourcepath .\NanoServer.wim -VHDPath .\nanoserver.vhdx
      Windows(R) Image to Virtual Hard Disk Converter for Windows(R) 10
      Copyright (C) Microsoft Corporation.  All rights reserved.
      Version 10.0.9000.0.amd64fre.fbl_core1_hyp_dev(mikekol).141224-3000 Beta
      ERROR  : You must specify an Edition or SKU index, since the WIM has more than one image.
      ERROR  : Valid edition names are:
      ERROR  :
      ERROR  :
      ERROR  : ScriptHalted
      INFO   : Log folder is C:\temp\Convert-WindowsImage\880ee7d3-b09c-4ded-8d09-5220890ee580
      INFO   : Closing Windows image...
      INFO   : Done.
      Notice the 2 blank lines? It should be:
       dism /get-wiminfo /wimfile:nanoserver.wim
      Deployment Image Servicing and Management tool
      Version: 10.0.10240.16384
      Details for image : nanoserver.wim
      Index : 1
      Description : <undefined>
      Size : 722,645,954 bytes
      Index : 2
      Description : <undefined>
      Size : 693,320,190 bytes
      Line 1735-1744 are probably the problem.
    • In the meantime, I have found a simple workaround to get the job done, so I thought I would share while we wait on an official codefix here -
      1. Use Disk Management MMC to Create and mount a New VHD. Assign a driver letter (like Z:)
      2. Use GimageX.exe (or ImageX if you prefer, but I'm a GUI guy) to Apply your custom (or default) Windows 10 .wim file to the driver letter assigned above (like Z:)
      3. Unmount the VHD back in Disk Manager and the create a new HyperV VM using the existing .vhd file. Also, mount the Win10 .iso file to the Virtual CD.
      4. Turn on the VM, it will boot to the .iso. Choose a language, Repair computer, etc. etc. until you can choose to repair startup/boot issues. This will fix the BCD for you. It will automatically reboot into the VHD and Windows proper.
      5. Done.
    • I was able to get this working for me on a WIM containing a single image from the command line (no UI).
      On line 4075, change:
      $Edition   = $openWim.Images[0].ImageFlags 
      $Edition   = $openWim.Images[0].ImageName
      When you make the change, the $Edition variable is populated with the image name contained within the WIM.  Otherwise the variable is $null and the script fails.
      Have yet to test with other scenarios.
  • ERROR : Cannot convert the "System.String[]" value of type "System.String[]" to type "System.Int32".
    3 Posts | Last post August 21, 2015
    • Still getting the same error on Windows 8.1, even after the correction that Gary suggested... Any ideas?
    • All I can suggest is follow the approach I took:
      Open the script in Powershell ISE, add your function call to the end of the file, set break points (try line 4092 for a start) and press F5. Examine variables, rinse and repeat.
      It's quite a pain as I didn't get any stacktraces showing where the exception was thrown from so I just had to narrow it down.
      Line 3269 is another good breakpoint - this is where the scripts writes the header text. If you see "Windows(R) Image to Virtual Hard Disk Converter for Windows(R) 10" then it at least got that far and you can single step from there.
      Good luck!
    • I'm using the convert-windowsimage.ps1 that come with TH3
      Still need to fix up the version stuff
      instead of -edition 1
      you need -edition 'CORESYSTEMSERVER_INSTALL'
      or fix up the TryParse to properly decode what edition 1 is
  • run command on windows 10,no output
    3 Posts | Last post August 17, 2015
    • I run the command line on windows 10 cmd:
      PowerShell.exe -Command set-ExecutionPolicy Unrestricted
      PowerShell.exe -Command .\Convert-WindowsImage.ps1 -SourcePath "d:\W10.WIM" -SizeBytes 80GB -VHDFormat VHDX -VHDType Dynamic -Edition 1 -VHDPath "aaa.vhdx" -VHDPartitionStyle GPT -BCDinVHD VirtualMachine -Verbose
      but, nothing happens, no error, Can anyone help me?
    • Try "Edition 1"
    • .\convert-windowsimage.ps1 is a function
      you have to load it first
      . .\Convert-windowsimage.ps1 
      notice the space between the periods
      Then the command will somewhat work (it is broken on some wim files)
  • ShowUI not doing anything on Windows 10
    2 Posts | Last post August 08, 2015
    • I run the ShowUI command on windows 10 : .\Convert-WindowsImage.ps1 -ShowUI
      and it's not doing anything, no error ... What gives?
    • Never mind. You need to change your example instruction.
  • Run Convert-WindowsImage.ps1 but no output
    1 Posts | Last post August 08, 2015
    • Hi
      I am trying to run Convert-WindowsImage.ps1 script from PowerShell but received on output or error messages. I have tried on 2 computer with different version of Power Shell including v4 / v5 with same results. Set Execution Policy to Unrestricted and ran in an Administrator PowerShell Console with same results
      Any Suggestions?
  • Convert-WindowsImage only supports Windows 7 and Windows 8 WIM files
    2 Posts | Last post August 05, 2015
    • I get the same error as Scott Smith:
      INFO   : Image  selected ()...
      ERROR  : Convert-WindowsImage only supports Windows 7 and Windows 8 WIM files.  The specified image does not appear to contain one of those operating systems.
      Is there a fix coming? 
    • Commenting out lines 4107-4110 does seem to fix the problem but then I get this error later on (last line):
      INFO   : Image  selected ()...
      INFO   : Creating sparse disk...
      INFO   : Attaching VHD...
      INFO   : Disk initialized with GPT...
      INFO   : Disk partitioned
      INFO   : System Partition created
      INFO   : Boot Partition created
      INFO   : System Volume formatted (with DiskPart)...
      INFO   : Boot Volume formatted (with Format-Volume)...
      INFO   : Access path (E:\) has been assigned to the System Volume...
      INFO   : Access path (F:\) has been assigned to the Boot Volume...
      INFO   : Applying image to VHD. This could take a while...
      ERROR  : Method invocation failed because [System.Object[]] does not contain a method named 'Apply'.
  • Fails to recognize Nano WIM File
    1 Posts | Last post August 05, 2015
    • Setup script to call the Convert-WindowsImage function to build a VHD file from the NanoServer.wim file in build 252 as follows. I used the version of Convert-WindowsImage that is provided with the 252 build.
      # Load the function
      . C:\temp\NanoServer\Convert-WindowsImage.ps1
      # Prepare variables
       $ConvertWindowImageParms = @{
          SourcePath     = "C:\temp\NanoServer\NanoServer.wim"
          Edition        = "Edition 1"
          VHDFormat      = "VHD"
      #produce the image
      $VHDs = Convert-WindowsImage @ConvertWindowImageParms
      It executes, but fails to build VHD file with the following message in the log file saying that it only supports Win7 & Win8 WIM files. Also pulled down latest copy from this site with the same result.
      Windows PowerShell transcript start
      Start time: 20150805115456
      Username: SAMM44\Administrator
      RunAs User: SAMM44\Administrator
      Machine: SAMM44 (Microsoft Windows NT 10.0.10252.0)
      Host Application: C:\Windows\system32\WindowsPowerShell\v1.0\PowerShell_ISE.exe
      Process ID: 3656
      PSVersion: 5.0.10252.0
      WSManStackVersion: 3.0
      CLRVersion: 4.0.30319.42000
      BuildVersion: 10.0.10252.0
      PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0.10252.0
      PSRemotingProtocolVersion: 2.3
      INFO   : Image  selected ()...
      PS>TerminatingError(): "Convert-WindowsImage only supports Windows 7 and Windows 8 WIM files.  The specified image does not appear to contain one of those operating systems."
      ERROR  : Convert-WindowsImage only supports Windows 7 and Windows 8 WIM files.  The specified image does not appear to contain one of those operating systems.
      INFO   : Log folder is C:\Users\ADMINI~1\AppData\Local\Temp\Convert-WindowsImage\4ac326d5-2b71-416c-9a52-db50bd1562d6
      INFO   : Closing Windows image...
      INFO   : Done.
      Windows PowerShell transcript end
      End time: 20150805115456
  • Windows 10 nano server boot fail
    1 Posts | Last post August 04, 2015
    • I made the vhd file but when I try to boot up my VS from it it says 'Boot failure. Reboot and Select proper Boot device or Insert Boot Media in selected Boot device'
  • windows server 2003 x64 standard sp2 / RHEL 5.11
    1 Posts | Last post August 03, 2015
    • I have the ISO fil of "windows server 2003 x64 standard sp2" and "RHEL 5.11".
      Do I have a chance to convert the ISO files of these two to VHD? 
      I have azure VM created in windows server 2008 datacenter / windows server 2012 datacenter.
      If i execute these power scripts in azure environment, willl it create me VHD as expected?
      Please share your knowledge on this.
71 - 80 of 154 Items