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


  • Problem on Windows 10 Fall Creators update (1709)
    1 Posts | Last post October 20, 2017
    • I have had this problem since upgrading to Windows 10 Fall Creators update (1709).  I am pretty sure the problem started after installing 1709 this week.  When the script runs, I get the following error:
      
      Exception calling "Apply" with "1" argument(s): "The directory or file cannot be created"
      
      full log:
      
      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 en_windows_server_2016_x64_dvd_9327751.iso...
      INFO   : Looking for E:\sources\install.wim...
      
      INFO   : Image 4 selected (ServerDataCenter)...
      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 (F:\) has been assigned to the System Volume...
      INFO   : Access path (\\?\Volume{4a8daf5b-08cc-499f-ba80-456d6f68cb38}\) has been assigned to the Boot Volume...
      INFO   : Applying image to VHDX. This could take a while...
      ERROR  : Exception calling "Apply" with "1" argument(s): "The directory or file cannot be created"
      INFO   : Log folder is C:\Users\Phil\AppData\Local\Temp\Convert-WindowsImage\ce2f5e7c-e52a-4e13-b296-fff0fa6e64af
      
      INFO   : Closing Windows image...
      INFO   : Closing VHDX...
      INFO   : Closing ISO...
      INFO   : Done.
      
  • 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
  • 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 :-(
  • 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.
21 - 30 of 154 Items