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
(168)
108,781 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
    3 Posts | Last post October 04, 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!
    • Hi folks,
      
      Sitting late hours and eyes get blurry, I finally found somthing interesting about this "$Edition = $openWim.Images[0].ImageFlags". Thanks whiggs3 point out an easy workaround.
      
      "But"
      
      My testing:
      
      1 - With VL media from Microsoft it works just fine to use the Edition = "ServerStandard" multiple edition (Indexes)
      
      2- I build a reference image with MDT as I use to do (With the same Image in test 1), and I loved the idea to convert it to a VHDx. Same base for SCCM and Hyper-V, now we talking basline.
       
      D'oh!!!!
      ERROR  : The variable cannot be validated because the value  is not a valid value for the Edition variable.
      
      The MDT WIM had only one Index and a ImageFlags (What I can see), but is it a single edition issue (bug)? It could be a MDT capture image issue? Looks like that. I start digging about WIM properties. Finally I reset the SKU FLAGS (ImageFlags) with old tool imagex/gimagex with the value Edition = "ServerStandard"
       
      Wolla!!
      Now does the Convert-WindowsImage.ps1 script work with $Edition = $openWim.Images[0].ImageFlags. This on a WIM file with just one Index, and use the Edition = "ServerStandard".
      
      The I get frustrated again when I was not able to set the SKU FLAGS (ImageFlags) with the DISM or DISM cmdlet. Is there someone know a more modern way to set the WIM SKU FLAGS (ImageFlags)?  
  • Make 4k aligned Image
    1 Posts | Last post September 20, 2017
    • How can i create a 4k aligned vhd image using this script? Is it possible to override some parameter to do so ?
  • A required privilege is not held by the client
    1 Posts | Last post September 11, 2017
    • Hi,
      
      By running:
      
      $wim = "C:\Image\image.wim"
      
      # Load (aka "dot-source) the Function 
      . .\Convert-WindowsImage.ps1 
      
      $VHDx = Convert-WindowsImage -SourcePath C:\Image\image.wim
      
      I get the error:
      ERROR  : Exception calling "Apply" with "1" argument(s): "A required privilege is not held by the client"
      
      The powershell is with administrator priviliges
      I ran also:
      Set-ExecutionPolicy Unrestricted;
      
      Does someone has an idea ?
      
      Thanks
  • Issues Running the script
    2 Posts | Last post September 08, 2017
    • when i run this below:
      .\Convert-WindowsImage.ps1 -SourcePath D:\OS's\ISO\WindowsServer2016.iso -VHDFormat VHDX -Edition Standard -VHDPartitionStyle GPT
      
      it does nothing. do not get an error or failure. Just moves on to the next line
      
      where would i see errors for this? 
      
      
      
    • it's a cmdlet now
  • Failure when Attempting WSE deployment
    3 Posts | Last post August 28, 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.
      
    • Mjmeans could answer me, if I could solve the problem, I'm having the same problem as you.
  • Error on Get-Volume line 4042 or 3408
    1 Posts | Last post August 25, 2017
    • Get-Volume : Parameter set cannot be resolved using the specified named parameters.
      
      If you're getting this error, you can fix it by replacing line 4042 (or 3408) with this...
          #$driveLetter = ($openIso | Get-Volume).DriveLetter
          $driveLetter = (Get-Volume -DiskImage $openIso).DriveLetter
      
      It appears that Get-Volume has changed some, or my Powershell is working differently.  I'm running Win 10 Build 16257 Enterprise.
      
      Enjoy!
      
  • 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)?
  • 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 :-(
1 - 10 of 136 Items