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


  • ObjectNotFound: (E:\sources\install.wim:String)
    2 Posts | Last post July 02, 2019
    • Hi,
      I wanted to use the script on a Windows 10 64-Bit Pro system. The ISO-Image is fresh made using the MediaCreationTool1903.exe which is provided by Microsoft to create ISO image for install from USB or DVD.
      
      I edited the script according to https://www.cbtechinc.com/make-your-windows-10-computer-versatile-by-using-vhdx-native-boot/
      
      When running the script using 
      Convert-WindowsImage -VHDFormat VHDX -SizeBytes 25GB -BCDinVHD NativeBoot -ExpandOnNativeBoot:$false -SourcePath c:\Temp\Windows_10_64-Bit_Pro_N.iso -VHDPath c:\Temp\win10_master.vhdx
      
      I get the error message
      
      Der Pfad "E:\sources\install.wim" kann nicht gefunden werden, da er nicht vorhanden ist.
      
      I include also the error protocol:
      
      nStart der Windows PowerShell-Aufzeichnung
      Computer: (Microsoft Windows NT 10.0.17134.0)
      Hostanwendung: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
      PSVersion: 5.1.17134.590
      PSEdition: Desktop
      
      INFO   : Opening ISO 2019-06-21_Windows_10_64-Bit_Pro_N_mit-Lizenz.iso...
      Resolve-Path : Der Pfad "E:\sources\install.wim" kann nicht gefunden werden, da er nicht vorhanden ist.
      In C:\Temp\2019-06-09_Convert-WindowsImage.ps1:174 Zeichen:43
      +             [ValidateScript({ Test-Path $(Resolve-Path $_) })]
      +                                           ~~~~~~~~~~~~~~~
          + CategoryInfo          : ObjectNotFound: (E:\sources\install.wim:String) [Resolve-Path], ItemNotFoundException
          + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.ResolvePathCommand
      PS>TerminatingError(Test-Path): "Das Argument kann nicht an den Parameter "Path" gebunden werden, da es NULL ist."
      ERROR  : Das Argument kann nicht an den Parameter "Path" gebunden werden, da es NULL ist.
      INFO   : Log folde
      
      What do I need to change to get the script running?
      
      Best Regards
      
      Georg
      
    • This is a common problem with this script and is fixed in my newest version. I collected most of the errors and solutions from the comments here and merged them with the newer version of the script https://www.powershellgallery.com/packages/Convert-WindowsImage/10.0
      
      It is under MIT-Licence and you can find it at github:
      
      https://github.com/x0nn/Convert-WindowsImage
      
      When there are more problems, you can file a Issue there.
      
      Best Regards
  • Why do we need WinPE installed in system, specially its version?
    1 Posts | Last post May 20, 2019
    • Hi,
      I'm Naveen, I work on automating the windows installation, it was everything working fine with last version of Convert-WindowsImage.ps1 but since its moved as inbuilt module in Powershell itself so I tried to use that module to avoid huge lines of code, but I started facing a problem, ie by the line 746 in Convert-WindowsImage.psm1 where it just needs version of WinPE running on the system that too to print it, which doesn't make any sense and for the sake of one that line why do we have to install winpe on the system.
      My problem is it was working fine without winpe but not now with the use of inbult module it is kinda necessary to install winpe.
      
      Apologies if I'm wrong as i'm not an expert, just my work stuck because of that blocker.
      
      Thanks and Regards
      naveen
  • Null value for Edition
    3 Posts | Last post March 04, 2019
    • 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
    • ^^^ this fixed the $null for edition variable for me.  Thanks.
  • Throws exception when opening WIM file
    1 Posts | Last post February 01, 2019
    • 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. ---> System.Management.Automation.ValidationMetadataException: The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
         at System.Management.Automation.ValidateNotNullOrEmptyAttribute.Validate(Object arguments, EngineIntrinsics engineIntrinsics)
         at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter, CompiledCommandParameter parameterMetadata, ParameterBindingFlags flags)
         --- End of inner exception stack trace ---
         at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
         at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
         at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
         at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
         at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
         at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
         at System.Management.Automation.ScriptBlock.InvokeWithPipeImpl(ScriptBlockClauseToInvoke clauseToInvoke, Boolean createLocalScope, Dictionary`2 functionsToDefine, List`1 variablesToDefine, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Object[] args)
         at System.Management.Automation.ScriptBlock.<>c__DisplayClass57_0.<InvokeWithPipe>b__0()
         at System.Management.Automation.Runspac
  • Re: Problem on Windows 10 Fall Creators update (1709)
    12 Posts | Last post January 16, 2019
    • 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..."
    • can confirm that the solution from cryptonym works on server2019.
      as stated from Rheimos you'll have to reload the function. 
  • Test it with 2019
    3 Posts | Last post January 16, 2019
    • I ran this on 2019 server trying to create a vhdx bootable GPT out of 2019 wim, in the middle of expansion I got this:
      PSVersion: 5.1.17763.134
      PSEdition: Desktop
      PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.17763.134
      BuildVersion: 10.0.17763.134
      CLRVersion: 4.0.30319.42000
      WSManStackVersion: 3.0
      PSRemotingProtocolVersion: 2.3
      SerializationVersion: 1.1.0.1
      **********************
      
      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 (G:\) has been assigned to the System Volume...
      INFO   : Access path (\\?\Volume{03c302fc-0764-4250-8711-a19c1b0735cb}\) 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"
      INFO   : Log folder is C:\Users\LocalAdmin\AppData\Local\Temp\Convert-WindowsImage\b791fc08-4654-4d6a-8fc9-f08e025c8f62
      
      INFO   : Closing Windows image...
      INFO   : Closing VHDX...
      INFO   : Done.
      **********************
    • First, THANK YOU for creating this script and process, I'm sure it's helped any people, however I was not able to get it to work  (opening the GUI gave me errors when selecting the wim file, after attempting to run it several times it stopped giving any errors, and just ignored my requests).  I instead searched for another way, and eventually found this Powershell script: Create-VHDX.ps1 here: https://deploymentbunny.com/2013/12/19/powershell-is-king-convert-wim-to-vhdvhdx-with-support-for-gen-1-and-gen-2-biosuefi-and-then-some/
      
      Following the instructions listed under "Converting the WIM file to the VHDX file" (first running Set-ExecutionPolicy Bypass) I was able to convert the WIM to VHDX.
    • same error here on server 2019
  • No Source Path Specified error
    3 Posts | Last post January 03, 2019
    • when I run this from the gui I have selected D:\winpe\install.wim, d:\winpe\winre.wim and d:\acronisrecoverype.iso and I get the same error :
      
      INFO   : Launching UI...
      INFO   : Opening ISO AcronisBootablePEMedia.iso...
      INFO   : Looking for ...
      ERROR  : No source path specified.
      INFO   : Log folder is C:\Users\shock\AppData\Local\Temp\Convert-WindowsImage\fa6b241f-5b8a-4585-b2f8-94875fca75e9
      INFO   : Done.
      
      No source path specified is what I get from all three attempts. the install.wim is from my windows 10 1809 installation media as is the winre.wim.  I was hoping to be able to convert non-windows install .iso and make a bootable .vhdx. Any help or assistance will be greatly appreciated. TIA 
    • Forgot to put the following from the log file:
      
      PS>TerminatingError(Test-Path): "Cannot bind argument to parameter 'Path' because it is an empty string."
      >> TerminatingError(Test-IsNetworkLocation): "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."
    • OK I figured it out. This program will not convert a non-windows installation iso image to a vhd(x). I had to run it from the command line :
      
      PS C:\WINDOWS\system32> convert-windowsimage -sourcepath D:\winpe\install.wim -workingdirectory D:\ -VHDType fixed -vhdformat vhdx -vhdpartitionstyle GPT  -edition Professional
      
      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   : Image 6 selected (Professional)...
      INFO   : Creating fixed disk...
      INFO   : Attaching VHDX...
      INFO   : Disk initialized with GPT...
      INFO   : Disk partitioned
      INFO   : System Partition created
      INFO   : Boot Partition created
      
      and now its just sitting there in the powershell window with the cursor blinking.
      I went into d:\  and the .vhdx is there so I guess it was created with the default name.
      
      I will search the web for an .iso to. vhd(x) conversion utility program. Thanks
  • does nothing
    4 Posts | Last post January 03, 2019
    • this is very frustrating, set the execution policy to unrestricted, executing the .ps1 does nothing
    • Thank You ..for you solution, work very well
    • from the PS command line type:
      . .\ConvertWindowsImage    <   that's  dot space dot backslash
      
      then from the PS command line type:
      
      \ConvertWindowsImage -ShowUI     
      
      This assume the ConvertWindowsImage.ps1 file is in C:\windows\system32
      
      and that you set-executionpolicy unrestricted -force first.
      hth
    • It should be :
      Convert-WindowsImage -ShowUI
      
      NOT
      
      \Convert-WindowsImage -ShowUI
  • Script is not running on any Device
    5 Posts | Last post November 28, 2018
    • I cannot run this script on different machines (W2012R2 or Win8.1)
      If i run the script, nothing happens.
      I tried several things. Powershell started as admin, i unlocked the file after downloading, i set the execution policy to unrestricted.
      
      No -ShowUI or -SourcePath ..... is working.
      
      Can anyone help me?
      
      Regards Sven
    • OK, my mistake.
      Here my own solution. :)
      Just copy and paste the following, to start the UI:
      
      set-executionpolicy unrestricted -force
      . .\Convert-WindowsImage.ps1
      convert-windowsimage -ShowUI
    • WORKED!!!
      http://virtualstation.azurewebsites.net/?p=9551
      
    • Thanks Marcel Otto, you saved my time.
      Worked!!!!!!!!!!!!!! YES!!!!!!!!!!!!!!!!!!!
      also I tried
      . .\Convert-WindowsImage.ps1 (space between . .\)
      convert-
      this will prompt for Convert-WindowsImage.ps1 
      then space and type -showui
    • this does not work for me
  • 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.  
      
1 - 10 of 154 Items