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


  • Failure when Attempting WSE deployment
    2 Posts | Last post March 13, 2017
    • Downloaded to c:\scripts folder, unblocked, ran the recommended command from admin command shell specified https://msdn.microsoft.com/en-us/library/windows/hardware/dn898458(v=vs.85).aspx.
      
      powershell -c "Set-ExecutionPolicy Unrestricted; C:\scripts\Convert-WindowsImage.ps1 -VHDFormat vhdx -sizebytes 127GB –sourcepath C:\OEMEssentials.iso -vhdpath C:\OEMEssentials.vhdx"
      
      Nothing happens. No error. No messages at all. Just returns to C: prompt.
      
      Open admin powershell and tried:
      
      Set-ExecutionPolicy Unrestricted; C:\scripts\Convert-WindowsImage.ps1 -VHDFormat vhdx -sizebytes 127GB –sourcepath C:\OEMEssentials.iso -vhdpath C:\OEMEssentials.vhdx
      
      Prompt for execution policy. Pressed Y and ether. Then nothing happens. No error. No messages at all. Just returns to the PS prompt.
      
      I don't understand what is wrong.
    • Convert-WindowsImage has been created as a function hence these are the commands that you would need to run.
      
      Set-ExecutionPolicy Unrestricted
      .'C:\scripts\Convert-WindowsImage.ps1'
      Convert-WindowsImage -VHDFormat vhdx -sizebytes 127GB –sourcepath C:\OEMEssentials.iso -vhdpath C:\OEMEssentials.vhdx
      
      You might need to add the "-Edition" and "-DiskLayout" to the last command.
      
  • Are we all in agreement that this script is broken?
    3 Posts | Last post March 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.
    • No, not in agreement.  Remember that it is created as a function.  Before you use the script, you need to dot source it so it defines a function called Convert-WindowsImage.  Then you simply use that as the cmdlet with the appropriate parameters and it works as expected.  If you read the revision log on the gallery home page for this script, you will see that the author converted it into a function.
    • Seems to me it is broken. Tim does not address the error Step_R reports. Not Dot-Sourcing the script would not generate a 'cannot call a mothod' error.
      I too get errors:
      Here's what I try:
      $ISO = 'C:\Builds\en_windows_server_2016_x64_dvd.iso'
      $VMConfig = 'H:\Vm\VMs'
      $VMVHD    = 'H:\Vm\Vhds'
      #Setup Hash table of parameters
      $ParamHt =[Ordered]  @{  
        SourcePath          = $ISO
        Edition             = 'ServerDataCenter' 
        RemoteDesktopEnable = $True  
        Passthru            = $True  
        VHDFormat           = 'VHDX'
        VHDPartitionStyle   = 'GPT'
      }  
      Import-Module -Name  C:\Convert-WindowsImage\10.0\Convert-WindowsImage.psd1
      Import-Module -Name Dism,CimCmdlets
      $VHDx = Convert-WindowsImage @ParamHt -Verbose
      
      The function runs OK, but I get these errors:
      Get-ItemProperty : Cannot find path 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\WinPE' because it does not exist.
      At C:\Convert-WindowsImage\10.0\Convert-WindowsImage.psm1:746 char:38
      + ... eVersion = (Get-ItemProperty -Path 'HKLM:\Software\Microsoft\Windows  ...
      +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : ObjectNotFound: (HKLM:\Software\...ntVersion\WinPE:String) [Get-ItemProperty], ItemNotFoundException
          + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand
       
      The property 'Version' cannot be found on this object. Verify that the property exists.
      At C:\Convert-WindowsImage\10.0\Convert-WindowsImage.psm1:746 char:21
      + 
      
      Convert-WindowsImage : The variable '$hyperVEnabled' cannot be retrieved because it has not been set.
      At C:\Users\Administrator\Documents\Recipe 13-4 - Create VM.ps1:28 char:9
      + $VHDx = Convert-WindowsImage @ParamHt -Verbose
      +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
          + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-WindowsImage
      
      IMHO - Another low quality broken script :-(
  • Cannot validate argument on parameter 'Path
    4 Posts | Last post March 02, 2017
    • 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.
    • Note that the GUI was deprecated in the latest release.  This is mentioned in the log file of changes.
  • Working As Expected
    1 Posts | Last post February 14, 2017
    • 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.
  • 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
  • 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...
      
1 - 10 of 128 Items