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


  • Re: Problem on Windows 10 Fall Creators update (1709)
    7 Posts | Last post Mon 10:27 AM
    • I have confirmed the problem is related to the 1709 release of Windows 10.  I created two brand new VMs, on running 1703 and the other 1709. 1703 works correctly. 1709 fails with
      
      ERROR  : Exception calling "Apply" with "1" argument(s): "The directory or file cannot be created"
      
       
    • Hi,
      I have encountered the same error. I have investigated that on VHDX despite creation of two volumes, there are apparently three. The script tries to copy Windows image to System Volume (that has 100MB only) instead of Boot Volume and that is the source of the error message.
      
      In your script I can see wrong path to Boot Volume (\\?\Volume{4a...)
      
      Quick and dirty solution: 
      
      In line 4220 of Convert-WindowsImage.ps1 change:
      $drive = $(Get-Partition -Disk $disk).AccessPaths[2]
      to
      $drive = $(Get-Partition -Disk $disk).AccessPaths[3]
      
      
    • I confirm this. You might find this test useful to decide which path to take (not 100% sure of the correct build number for this):
      
                  function Test-WindowsVersion1709
                  {
                      $os = [System.Environment]::OSVersion.Version
                      $is1709 = ($os -ge '10.0.16299.0')
                      Write-W2VTrace "is local machine Windows 10 version 1709 or Higher? $is1709"
                      return $is1709
                  }
      
    • The fix for the "Apply" with "1" argument error in Win10 1709 appears to be due to a misuse of the arrays. This is totally unrelated to the old "1 image" bug. I changed line 4216 
      from: $driveSystem = $(Get-Partition -Disk $disk).AccessPaths[1]
      to: $driveSystem = $(Get-Partition -Disk $disk)[1].AccessPaths[0]
      
      line 4220 
      from: $drive = $(Get-Partition -Disk $disk).AccessPaths[2]
      to: $drive = $(Get-Partition -Disk $disk)[2].AccessPaths[0]
      
      line 4229
      from: $drive = $(Get-Partition -Disk $disk).AccessPaths[1]
      to: $drive = $(Get-Partition -Disk $disk)[1].AccessPaths[0]
      
      This indexes into the partition list, then gets the 1st (zero based) entry in the list. Before I think it assumed the list only could have 1 entry per partition. It now seems to have 2 for each partition. I have not yet confirmed this works on older OS, but it appears to fix the 1709 issue. Line 4229 is also untested, as I only am doing VMs, but it should be correct.
      
      Hopefully some of the fixes in the comments section make it into the download codebase. This script is a real time saver.
      
    • I think I missed one...
      Line 4207 is:
      $drive           = $(Get-Partition -Disk $disk).AccessPaths[0]
      and likely also needs my same fix:
      $drive           = $(Get-Partition -Disk $disk)[0].AccessPaths[0]
      
      I really won't be testing this, since it is in the MBR partitioning section. The same logic should still apply I believe though.
      
    • I installed a 1703 Win10 to test my suggested fix on an older release, and it worked the same. So my proposed changes are not specific to running on 1709, and can safely be used. No need to test what OS you are running if implemented in this manner.
    • I can confirm that the fix of cryptonym solved the problem. Thx a lot!
  • Is there a workaround for Win 10 1709 (Fall Creators)
    1 Posts | Last post November 09, 2017
    • As noted by Phil Bolduc, 1709 breaks this script.  Is anyone aware of a workaround or replacement? 
  • Error with Windows 7 image
    2 Posts | Last post October 27, 2017
    • I'm getting an error when I try to process a Windows 7 Professional image:
      VERBOSE: isUserAdmin? True
      VERBOSE: is Windows 8 or Higher? True
      VERBOSE: Temporary VHD path is : c:\downloads\e3b150e3-17aa-4c45-bd83-8fe76e062618.vhd
      INFO   : Opening ISO en_windows_7_professional_x86_dvd_x15-65804.iso...
      INFO   : Looking for E:\sources\install.wim...
      INFO   : Image  selected ()...
      
      PS>TerminatingError(): "Convert-WindowsImage only supports Windows 7 and Windows 8 WIM files.  The specified image does not appear to contain one of those operating systems."
      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\DPCADM~1.TES\AppData\Local\Temp\3\Convert-WindowsImage\e3b150e3-17aa-4c45-bd83-8fe76e062618
      INFO   : Closing Windows image...
      INFO   : Closing ISO...
    • OK, sorted this issue. Script started working
  • 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
  • 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 29, 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!
      
1 - 10 of 140 Items