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
(172)
123,580 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)
    11 Posts | Last post Wed 6:00 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!
    • On Server 2012 R2 it does absolutely nothing.
      
      Return to prompt, no error either
    • Sadly no answer helped, not from cryptonym and/or Wojtek TM
      Changed the lines, still get the error:
      
      INFO   : Image 1 selected (ServerStandardACor)...
      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 (G:\) has been assigned to the System Volume...
      INFO   : Access path (\\?\Volume{9c614389-0dc2-424c-ab25-8411d0362aa4}\) has been assigned to the Boot Volume...
      INFO   : Applying image to VHDX. This could take a while...
      PS>TerminatingError(ForEach-Object): "Exception calling "Apply" with "1" argument(s): "The directory or file cannot be created""
      ERROR  : Exception calling "Apply" with "1" argument(s): "The directory or file cannot be created"
      
    • scerazy,
      I kept getting the same error despite I applied cryptonym's changes and reloaded the script. I know it sounds silly, but it turned out I haven't actually reloaded the changes: I used
      .\Convert-WindowsImage.ps1 instead of
      . .\Convert-WindowsImage.ps1
      After actually reloading the script it worked.
    • HI ,
      
      I Change From Line 4250 to 4261
      
      
                                  $partitionSystem | Add-PartitionAccessPath -AssignDriveLetter 
                                  Start-Sleep -s 3
                                  $partitionSystem = Get-Partition -DiskNumber $partitionSystem.DiskNumber  -PartitionNumber $partitionSystem.PartitionNumber
                     
                                  $driveSystem     = $partitionSystem.AccessPaths[0]
                                  Write-W2VInfo "Access path ($driveSystem) has been assigned to the System Volume..."
      
                                  $partition       | Add-PartitionAccessPath -AssignDriveLetter  
                                  Start-Sleep -s 3
                                  $partition = Get-Partition -DiskNumber $partition.DiskNumber  -PartitionNumber $partition.PartitionNumber
                                  $drive           = $partition.AccessPaths[0]
                                  Write-W2VInfo "Access path ($drive) has been assigned to the Boot Volume..."
  • Windows Server 2019 Error
    1 Posts | Last post November 01, 2018
    • I tried to convert an ISO of Windows Server 2019 and received the 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"
      
      To troubleshoot the issue I removed the "-Edition" flag from my function call.  This caused the script to generate an error that listed the acceptable edition values.
      
      To fix this issue I change my parameters that I had used for Windows Server 2016
      
      From:  "-Edition ServerDataCenterCor" 
      
      To:  "-Edition ServerDataCenterCore"
      
      Hope this helps anyone that runs into this error as well.  
      
  • Error at Applying Image to VHDX
    1 Posts | Last post October 24, 2018
    • I have got an Windows 10 1803 WIM trying to add the conversion but failing with the following error. 
      
      INFO   : Applying image to VHDX. This could take a while...
      PS>TerminatingError(ForEach-Object): "Exception calling "Apply" with "1" argument(s): "A required privilege is not held by the client""
      ERROR  : Exception calling "Apply" with "1" argument(s): "A required privilege is not held by the client"
      
      Have elevated Powershell 
      
      Anyone else resolved the error?
      
      Bruce
  • Null value for Edition
    2 Posts | Last post October 12, 2018
    • Even using the -Edition switch and specifying any edition I get the following error message as if I had not specified one at all.
      ERROR  : The variable cannot be validated because the value $null is not a valid value for the Edition variable. 
    • I had the same issue with Edition on Win10 -- the fix for this is at line 4075:
      
      Change
                          $Edition   = $openWim.Images[0].ImageFlags
      to
                          $Edition   = $openWim.Images[0].ImageName
  • ERROR : The system cannot find the file specified.
    2 Posts | Last post September 04, 2018
    • 
      
      
      
      
      
      INFO   : Image 1 selected (Core)...
      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 (G:\) 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...
      ERROR  : This command cannot be run due to the error: The system cannot find the file specified.
      INFO   : Log folder is C:\Users\NewUser\AppData\Local\Temp\Convert-WindowsImage\fd7fe739-61fc-4abb-acd1-bbcb7fbf43ef
      
      INFO   : Closing Windows image...
      INFO   : Closing VHDX...
      INFO   : Done.
      
      ANY IDEAS? THANKS
    • Hi Chawoja,
      
      Try to check if bcdedit.exe is accessible - the script uses it to make image bootable.
  • Problem on Windows 10 1709
    1 Posts | Last post May 03, 2018
    • I changed the script as per Cryptonym dec 06 2017 and still get this error
      Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
      Process ID: 2272
      PSVersion: 5.1.16299.251
      PSEdition: Desktop
      PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.16299.251
      BuildVersion: 10.0.16299.251
      CLRVersion: 4.0.30319.42000
      WSManStackVersion: 3.0
      PSRemotingProtocolVersion: 2.3
      SerializationVersion: 1.1.0.1
      **********************
      INFO   : Opening ISO WinPro1709.ISO...
      INFO   : Looking for E:\sources\install.wim...
      
      INFO   : Image 5 selected (Professional)...
      INFO   : Creating sparse disk...
      INFO   : Attaching VHD...
      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 (\\?\Volume{dc0a76b5-f958-4bb4-974b-b39be5e62ca2}\) has been assigned to the System Volume...
      INFO   : Access path () has been assigned to the Boot Volume...
      INFO   : Applying image to VHD. This could take a while...
      PS>TerminatingError(ForEach-Object): "Exception calling "Apply" with "1" argument(s): "Value cannot be null.
      Parameter name: ApplyToPath""
      ERROR  : Exception calling "Apply" with "1" argument(s): "Value cannot be null.
      Parameter name: ApplyToPath"
      INFO   : Log folder is C:\Users\bobby\AppData\Local\Temp\Convert-WindowsImage\af2316fb-ffed-49c4-9cc8-8ca2a4f3c3ab
      
      INFO   : Closing Windows image...
      INFO   : Closing VHD...
      INFO   : Closing ISO...
      INFO   : Done.
  • Need Steps- How do I create a Windows 10 Image as .vhdx and use that as a boot option on another Windows 10 machine
    1 Posts | Last post April 10, 2018
    • I wish to take an image backup as .vhdx from one of my Windows 10 machines, and then use that .vhdx (either as bootup (preferred) or in Hyper-V") to start using that as my image from this heavy demo machine.
      
      Please suggest!
      Tara
  • wmi with single edition
    1 Posts | Last post February 13, 2018
    • In my wmi, there is only one image, and ImageFlags is null. So, the powershell was failing when assigning ImageFlags to $Edition. I amended the code (near line 4073):
                      # If there's only one image in the WIM, just select that.
                      if ($openWim.Images.Count -eq 1) { 
                          if ([String]::IsNullOrEmpty($openWim.Images[0].ImageFlags)) {
                              $Edition   = $openWim.Images[0].ImageName 
                          } else {
                              $Edition   = $openWim.Images[0].ImageFlags
                          }
                          $openImage = $openWim[$Edition]
                      } else { ...
      
      hope this helps... great tool by the way, saved me a ton of time.
  • Error with Windows 7 image
    4 Posts | Last post February 05, 2018
    • 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
    • How did you solve it? I have the same question?
    • Seems to be the -RemoteDesktopEnable switch only works on Win7/8 WIM images.
  • Failure when Attempting WSE deployment
    4 Posts | Last post January 22, 2018
    • 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.
    • This is what I had to use.  
      . ./Convert-WindowsImage
      Convert-WindowsImage -VHDFormat vhdx -sizebytes 127GB –sourcepath I:\sou
      rces\install.wim -Edition ServerDatacenter -vhdpath C:\VHDs\win2012r2trm.vhdx.  And it worked like a charm.  your source paths and vdhpaths will be different of couse.
1 - 10 of 148 Items