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


  • to all of those who receive error when running script
    2 Posts | Last post June 12, 2017
    • the resolution to this problem has already been found and is detailed in these comments if you would take the time to look before posting.  to make it easier for you, i have included the resolution here:
      There is a bug in this version that only occurs when being used against a WIM file with a single edition. The Server 2016 TP4 Nano Server WIM only contains a single edition.
      The bug starts on line 4075:
      $Edition   = $openWim.Images[0].ImageFlags
      It looks like the ImageFlags property is being used when it should be the ImageName or ImageIndex property to reference the edition. In Nano Server TP4 the ImageFlags is $null which causes an error to occur.
      ERROR: The variable cannot be validated because the value $null is not a valid value for the Edition variable.
      Changing references to this property to ImageName resolves the issue.
      in other words, in whatever text editor you use, go to line 4075 where you will see
      $Edition   = $openWim.Images[0].ImageFlags
      and replace that line with 
      $Edition = $openWim.Images[0].ImageIndex
      or
      $Edition = $openWim.Images[0].ImageName
      That resolves the issue and lets you dot source the script.
    • Thanks Dante!
  • to all of those who receive error when running script
    1 Posts | Last post June 01, 2017
    • the resolution to this problem has already been found and is detailed in these comments if you would take the time to look before posting.  to make it easier for you, i have included the resolution here:
      There is a bug in this version that only occurs when being used against a WIM file with a single edition. The Server 2016 TP4 Nano Server WIM only contains a single edition.
      
      The bug starts on line 4075:
      $Edition   = $openWim.Images[0].ImageFlags
      
      It looks like the ImageFlags property is being used when it should be the ImageName or ImageIndex property to reference the edition. In Nano Server TP4 the ImageFlags is $null which causes an error to occur.
      ERROR  : The variable cannot be validated because the value $null is not a valid value for the Edition variable.
      
      Changing references to this property to ImageName resolves the issue.
      
      Note: This incorrect property is referenced in several places.
      
      in other words, in whatever text editor you use, go to line 4075 where you will see
      $Edition   = $openWim.Images[0].ImageFlags
      and replace that line with 
      $Edition   = $openWim.Images[0].ImageIndex
      or
      $Edition   = $openWim.Images[0].ImageName
      That resolves the issue and lets you dot source the script.
  • Implementing unattend.xml
    1 Posts | Last post May 12, 2017
    • Wish I had found this script before now.  Performs beautifully on Server 2012 R2 iso on a Windows 10 Creators Edition machine.
      I have tweaked the script and also use a different script to inject updates.  
      Remember, if you are running this from Powershell ISE, you must CD into the working directory first.
      
      Anyway, my question is - How do I implement an unattend.xml file during the build of the vhdx?  Can I grab and modify my tested unattend.xml from my MDT 2013 deployment share?
      
      Thanks for a fantastic utility!!
      
      Mike
      #######################################################
      
      . .\Convert-WindowsImage.ps1
      
      $ConvertWindowsImageParam = @{  
          SourcePath          = "d:\isos\SW_DVD9_Windows_Svr_Std_and_DataCtr_2012_R2_64Bit_English_-4_MLF_X19-82891.ISO"  
          RemoteDesktopEnable = $True  
      #    Passthru            = $True
          SizeBytes = 100GB
          Edition    = @("ServerStandard")
          Feature = @("NetFX3","NetFx3ServerFeatures","VolumeActivation-Full-Role")
      }  
      # Produce the images 
      $VHDx = Convert-WindowsImage @ConvertWindowsImageParam -ErrorAction Ignore
  • Doesn't appear to support Windows 10
    1 Posts | Last post April 26, 2017
    • The function fails when trying to open a Windows 10 (1703) ISO or default.wim file by saying it can only operate on a Windows 7 or Windows 8 image. There is no reference to Windows 10 in the function code or comments. Is it possible that the current link does not link to the right version (Version 10)?
  • 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.
1 - 10 of 132 Items