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.7 Star
(165)
98,593 times
Add to favorites
Storage
6/19/2015
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Working As Expected
    1 Posts | Last post Tue 5:10 PM
    • Server 2012 R2 and 2016 images converted successfully, with 2012 R2 being a volume license copy.  Win10 did not work, but it appears that the script doesn't know what to do with "install.esd" file that replaced the WIM file in the Nov/Dec 2015 update, so I'm not really bothered by that part.
      
      For Server 2016, it told me what $Edition was expecting...
      
      ERROR  : Valid edition names are:
      ERROR  :   ServerStandardEvalCore
      ERROR  :   ServerStandardEval
      ERROR  :   ServerDataCenterEvalCore
      ERROR  :   ServerDataCenterEval
      
      But for 2012 R2 it threw the "only Win7/Win8 WIM files are supported" error .  After doing a little dissection, I mounted 2012 R2's ISO then ran...
      
      $SourcePath = "I:\sources\install.wim"
      $openWim = New-Object WIM2VHD.WimFile $SourcePath
      $openWim.Images
      
      The "ImageFlags" in the list of editions is what it is expecting, but like I said, it doesn't always read the flags and let you know.  When all said and done (runnning as Admin)...
      
      Convert-WindowsImage -SourcePath 'C:\Users\xxx\Downloads\Server 2012 R2.ISO' -VHDPath 'C:\Users\xxx\Downloads\Server_2K12.vhdx' -Edition 'ServerStandard'
      
      INFO   : Opening ISO Server 2012 R2.ISO...
      INFO   : Looking for G:\sources\install.wim...
      INFO   : Image 2 selected (ServerStandard)...
      INFO   : Creating sparse disk...
      INFO   : Attaching VHDX...
      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 (H:\) has been assigned to the System Volume...
      INFO   : Access path (J:\) has been assigned to the Boot Volume...
      INFO   : Applying image to VHDX. This could take a while...
      INFO   : Signing disk...
      INFO   : Image applied. Making image bootable...
      INFO   : Drive is bootable. Cleaning up...
      INFO   : Closing VHDX...
      INFO   : Closing Windows image...
      INFO   : Closing ISO...
      INFO   : Done.
  • Cannot validate argument on parameter 'Path
    3 Posts | Last post Tue 1:23 PM
    • So I run the Powershell as admin, I run the following
      set-executionpolicy unrestricted -force
      . .\Convert-WindowsImage.ps1
      convert-windowsimage -ShowUI
      
      I get the GUI I select my WIM as the source and It throws a unexpected exception with the following.. PLEASE HELP
      
      
      System.Management.Automation.ParameterBindingValidationException: Cannot validate argument on parameter 'Path'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. ---> 
    • same error!!
      unable tu select SKU and unable to convert images using GUI
      
      
      hope this  this will help
      INFO   : Launching UI...
      ERROR  : No source path specified.
      INFO   : Log folder is C:\...\Temp\Convert-WindowsImage\c82ff142-a1fc-4346-8aa2-18c64d82095d
      INFO   : Done.
    • I also get the same error.
  • The Current Version repo :
    1 Posts | Last post February 10, 2017
    • 
      Well, this is the one I use with win10 and it seems to be updated regulary :
      
      https://github.com/Microsoft/Virtualization-Documentation/tree/master/hyperv-tools/Convert-WindowsImage
  • Are we all in agreement that this script is broken?
    1 Posts | Last post February 05, 2017
    • Win 10 1607. Imported the function, but every time I try to run it I simply get "ERROR: You cannot call a method on a null-valued expression."
      
      Also tried on a 2012 R2 server with the same results. 
      
      So how does one convert a WIM to VHD? I feel like it shouldn't be this difficult, but here I am.
  • does this script is working at all?
    2 Posts | Last post January 27, 2017
    • does this script is working at all? I tried and nothing is happening.
    • Mark, ran into the same problem as you did. You have to comment out lines 1, 2, 3 and 4565 like below:
      
      1: #Function
      2: #Convert-WindowsImage
      3: #{
      4565: #}
      
      Hope this helps.
  • Maybe,,, it has a bug in using $Edition variable
    4 Posts | Last post January 13, 2017
    • "$Edition = $PSItem" in the below has a problem,
      
      "
      $Edition | ForEach-Object -Process {
      
          $Edition = $PSItem
          
          if ([Int32]::TryParse($Edition, [ref]$null)) {
              $openImage = $openWim[[Int32]$Edition]  // throw exceptions in some cases
          } else {
              $openImage = $openWim[$Edition]
          }    
      
          ...[omitted for brevity]...
      }
      "
      
      This seems to be fixed like this,
      
      "
      $Edition | ForEach-Object -Process {
      
          $editionItem = $PSItem    // define $editionItem separetely
          
          if ([Int32]::TryParse($Edition, [ref]$null)) {
              $openImage = $openWim[[Int32]$editionItem]  // use $editionItem
          } else {
              $openImage = $openWim[$Edition]
          }    
      
          ...[omitted for brevity]...
      }
      "
      
    • Yes, the Edition variable is defined as "String Array" by mistake in line 176 and must be defined as "String".
      
      174  [Parameter(ParameterSetName="SRC")]
      175  [Alias("SKU")]
      176  [string[]]
      177  [ValidateNotNullOrEmpty()]
      178  $Edition,
      
      Delete the extra [] and fix line 176 to:
      176  [string]
      
      After this correction the script can accept the Edition Parameter as Index number or name.
    • I'm still getting the error (Windows 10 Enterprise 1607 OS running PowerShell as admin converting Windows 10 Enterprise 1607, Windows Server 2012 R2, or Windows Server 2016 so far):
      Cannot bind argument to parameter 'Path' because it is an empty string. I have tried individually and together both of the modifications listed to lines 176 and 4190. Any ideas?
      BTW - Amazing script! I really miss it now that it's not working for me.
    • Tried to apply changes but still getting the same error (Windows 10 pro 1607 )
  • Windows 10.WIM
    1 Posts | Last post January 03, 2017
    • Is V10 of this script supposed to work with a Windows 10.WIM file? Each time I try to run it I get:
      
      PS C:\> convert-windowsimage -SourcePath "C:\WIN10\Win10R1.3_Base.wim" -Edition Enterprise
      
      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
      
      
      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.
      INFO   : Log folder is C:\Users\broregan\AppData\Local\Temp\Convert-WindowsImage\e2cbd0fd-beff-4f9a-874f-968b488497a1
      
      INFO   : Closing Windows image...
      INFO   : Done.
  • Can't get passed line 4064
    1 Posts | Last post December 29, 2016
    • Hi,
      I am not much of a coder so I don't really understand what this portion of the script is trying to do and because the code it wants to load is all passed as a parameter I can't debug it.
      the line 4064 contains
      $openWim     = New-Object WIM2VHD.WimFile $SourcePath
      
      the error is:
      ERROR  : Exception calling ".ctor" with "1" argument(s): "An attempt was made to load a program with an incorrect format"
      
      I am running the script using the following command
      Convert-WindowsImage -SourcePath "E:\Windows ISO\Windows 10 1507.iso" -VHDPath "E:\NativeBoot\StagingVHDXDeploy\Windows10.vhdx" -SizeBytes 40GB -VHDFormat VHDX -VHDType Dynamic -Edition 'Windows 10 Pro' -VHDPartitionStyle GPT -BCDinVHD NativeBoot -RemoteDesktopEnable:$true
      
      thanks
      Steve
  • Server 2016 ISO version
    1 Posts | Last post December 21, 2016
    • Thanks for this script!!
      
      Gernal feedback - Won't run on an Evaluation version of Server 2016 ISO but will run on Server 2016 ISO downloaded from MS Partner benefits site.  
      
      Found through the Jack Stromberg site
      http://jackstromberg.com/2016/06/how-to-deploy-hub-licensed-vms-in-azure/deploy-from-template/
      
      ERROR script
      PS C:\support> Convert-WindowsImage -SourcePath "c:\support\14393.0.160715-1616.RS1_RELEASE_SERVER_EVAL_X64FRE_EN-US.ISO
      " -Edition serverDatacenter -vhdpath c:\support\2016-HUB.vhd -vhdformat VHD -SizeBytes 40GB
      
      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
      
      INFO   : Opening ISO 14393.0.160715-1616.RS1_RELEASE_SERVER_EVAL_X64FRE_EN-US.ISO...
      INFO   : Looking for F:\sources\install.wim...
      
      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.
      
      
      
      
      SUCCESS script
      
      PS C:\support> Convert-WindowsImage -SourcePath "SW_DVD9_Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_English_-2_MLF_X21
      -22843.ISO" -VHDFormat VHD -Edition "ServerDataCenter" -VHDPartitionStyle MBR -BCDinVHD NativeBoot -ExpandOnNativeBoot:$
      false -RemoteDesktopEnable -Verbose
      
      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
      
      VERBOSE: isUserAdmin? True
      VERBOSE: is Windows 8 or Higher? True
      VERBOSE: Temporary VHD path is : C:\support\14d846cb-5afc-4cf1-a3a1-15cc3b010872.vhd
      INFO   : Opening ISO SW_DVD9_Win_Svr_STD_Core_and_DataCtr_Core_2016_64Bit_English_-2_MLF_X21-22843.ISO...
      INFO   : Looking for F:\sources\install.wim...
      
      INFO   : Image 4 selected (ServerDataCenter)...
      INFO   : Creating sparse disk...
      
  • Parameter help/description is not always correct
    1 Posts | Last post December 20, 2016
    • Heads up,
      
      the parameter help for -VHDPartitionStyle says that by default the script creates a VHDX for a Gen-1 VM in Hyper-V (by using the MBR disk layout). This is not true - when you omit the parameter, the script chooses the GPT layout. Thus, the VHDX can only be used for a Gen-2 VM.
      
      Tested on Windows Server 2016 with a Server 2016 ISO. Here's my command line for reference:
      
      Convert-WindowsImage -SourcePath "H:\ISO\de_windows_server_2016_x64_dvd_9327757.iso" -Edition ServerDataCenter -vhdpath H:\VM\MeinServer.vhdx -vhdformat VHDX -SizeBytes 40GB
      
      And here's what the script says about the disk layout:
      
      INFO   : Attaching VHDX...
      INFO   : Disk initialized with GPT...
      INFO   : Disk partitioned
      INFO   : System Partition created
      INFO   : Boot Partition created
      
1 - 10 of 127 Items