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
142,253 times
Add to favorites
E-mail Twitter Digg Facebook
  • Metadata error and edition error
    2 Posts | Last post May 14, 2014
    • I have installed and setup Windows 8.1 on a desktop, installed some apps and Windows updates.  I ran sysprep.exe and used the Generalize option.  Then I captured the image using imagex that I have always used to capture Windows 7 images.  When I use this script to convert the .wim file it tells me that it is unable to read the metadata. There is a message box after that with the details but it is too much to post here.
      If I click continue, I get this: Error : The variable cannot be validated because the value  is not a valid value for the Edition variable.  
    • I had to replace a section with the following to get around this error -
              # If there's only one image in the WIM, just selected that.
              if ($openWim.Images.Count -eq 1) { 
                  $Edition   = $openWim.Images[0].ImageEditionID
                  $openImage = $openWim.Images[0]
              } else {
  • Drive letter usage
    2 Posts | Last post May 06, 2014
    • Hi All,
      I've created a simple script to create both gen2 and gen1 VHD(X)s from an ISO (for 2012R2 & 2012) and seem to have found a bug with the gen2 VHDX creation.  At the end of creating the VHDX (successfully), the drive letter that the SYSTEM partition is mapped to does not get dismounted/removed (the OS partition does).  I cannot see a way to remove it. There is no eject option when you right-click it and using DISM or PowerShell commands to unmount the image doesn't work either.  After creating a few images in a row, I start to run out of drive letters.  The only way to clear them is to reboot.
      Any ideas??
    • Please share the exact command line you're running as well as your host OS info. I have never observed anything like this before.
  • ERROR : При задании файла драйвера рекурсия недопустима
    1 Posts | Last post April 18, 2014
    • Добрый день. Спасибо за сценарий, он прекрасен.
      Как правильно задавать драйвер устройства хранения данных? Указываю -Driver X:\VHD\Win2k12\megasas2.inf, и получаю:
      INFO   : Adding Windows Drivers to the Image
      ПОДРОБНО: Версия командлетов PowerShell системы DISM
      ПОДРОБНО: Версия конечного образа 6.3.9600.17031
      ERROR  : При задании файла драйвера рекурсия недопустима
      Упражнялся с драйвером для 2012 с сайта Intel из
  • What is wrong?
    1 Posts | Last post April 17, 2014
    • Is there any mistake? What i have to do?
      Windows(R) Image to Virtual Hard Disk Converter for Windows(R) 8
      Copyright (C) Microsoft Corporation.  All rights reserved.
      Version 6.3.9600.7.amd64fre.fbl_core1_hyp_dev(mikekol).140217-3000 Release to Web
      INFO   : Launching UI...
      INFO   : Opening ISO SW_DVD5_Windows_Svr_Std_and_DataCtr_2012_R2_64Bit_German_Core_MLF_X19-05184.ISO...
      INFO   : Looking for E:\sources\install.wim...
      INFO   : Scanning WIM metadata...
      INFO   : Image 1 selected (ServerStandardCore)...
      INFO   : Creating sparse disk...
      INFO   : Attaching VHD...
      INFO   : Disk initialized with MBR...
      INFO   : Disk partitioned...
      Format-Volume : Mindestens einer der an die Methode übergebenen Parameterwerte war ungültig.
      In C:\Temp\Convert-WindowsImage.ps1:4106 Zeichen:26
      +             $volume    = Format-Volume -Partition $partition -FileSystem NTFS -F ...
      +                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidArgument: (MSFT_Volume (Ob...3-b049-0025...):ROOT/Microsoft/...age/MSFT_Volume) [
         Format-Volume], CimException
          + FullyQualifiedErrorId : MI RESULT 4,Format-Volume
      INFO   : Volume formatted...
      INFO   : Access path (F:\) has been assigned...
      INFO   : Applying image to VHD. This could take a while...
      ERROR  : Ausnahme beim Aufrufen von "Apply" mit 1 Argument(en):  "The WIM cannot be applied because the specified direct
      ory was not found."
      INFO   : Log folder is C:\Users\JESSE~1.REP\AppData\Local\Temp\Convert-WindowsImage\ba196671-b04f-42f7-8623-d3100091bff4
      INFO   : Closing Windows image...
      INFO   : Closing VHD...
      INFO   : Done.
      PS C:\Temp>
  • Can this target an existing volume?
    6 Posts | Last post April 03, 2014
    • Is there any way to make this target an existing volume instead of creating a VHD?  I'm plowing through the code, but I'm not so hot at C#.
    • @MrConst
      THANKS! your Suggestion to use GimageX helped!!
    • Hi Jordan Mills,
      What's your ultimate goal? Why would you want to apply an image to an existing volume?
      Anyway, I think the built-in DISM feature /Apply-Image should work perfectly for you. Please read at
    • I may be wrong, but the idea would be to pre-create an empty fixed VHDX, and then apply Windows Image to it (by using your script)? At least this is what I am looking for...this would enable quick automated creation of virtual machines. 
      Is this possible, or are there plans to enable this in feature versions?
    • > to pre-create an empty fixed VHDX, and then apply Windows Image to it 
      this is exactly what the entire Convert-WindowsImage script is all about :)
    • Yes, but if your script could be able to use an existing fixed empty VHD(X), and just apply a Windows to it...then it would complete much quicker. 
      For example, if we want to create a 40GB fixed disk, this takes couple of, we could pre-create this disk during off-peak hours, and provide it to your script as an input parameter.
  • Unable to process new WIM
    1 Posts | Last post April 01, 2014
    • We inject patches and other software and re-create our WIM. Before we used to used ImageX and the resulting WIM worked fine with this script. We now moved to using DISM.The WIM produced by DISM does play nice with this script if the given -Edition is a string (ServerStandard). It works if -Edition is the index. The resulting error from the script:
      ERROR  : The specified edition does not appear to exist in the specified WIM.
      ERROR  : Valid edition names are:
      ERROR  :   
      ERROR  :   
      ERROR  :   
      ERROR  :   
      ERROR  :   
      ERROR  : ScriptHalted
      In the script, the statement "$openImage = $openWim[$Edition]" is where things do not work.
      Looking at the DISM produced WIM using WIMtoVHD included with the script shows some missing properties, but the ImageEditionId is correct (But not the ImageFlags):
      Handle                  : WIM2VHD.NativeMethods+WimImageHandle
      ImageIndex              : 1
      ImageName               : Windows Server 2012 SERVERSTANDARD
      ImageEditionId          : ServerStandard
      ImageFlags              :
      ImageProductType        : ServerNT
      ImageInstallationType   : Server
      ImageDescription        : Windows Server 2012 SERVERSTANDARD
      ImageSize               : 15065565580
      ImageArchitecture       : AMD64
      ImageDefaultLanguage    : en-US
      ImageVersion            : 6.2.9200.16384
      ImageDisplayName        :
      ImageDisplayDescription :
  • Question regarding new /Feature switch
    2 Posts | Last post April 01, 2014
    • Can you please provide some more info about the new /Feature switch? 
      For instance, how do I install WebServer role and all the features it includes? WIth DISM this would require using the /All switch, but when I try to use it with your script it doesn't work (ERROR  : Feature name IIS-WebServer /All is unknown.).
      Also, is it possible to install multiple features at once? What would be correct syntax for this?
      Thanks once again for your fantastic script.
    • What -Feature parameter is doing, is passing through it value directly to Enable-WindowsOptionalFeature (
      Thus, it accepts exactly the same values as the abovementioned cmdlet.
      Currently, only a single value is supported. But this is a good point. I will add multiple values support in the next update.
  • Hi all
    3 Posts | Last post March 20, 2014
    • Looking for some insight into a strange issue.
      Using this script within another function, in the ISE.  I essentially run this:
      C:\path\to\Convert-WindowsImage.ps1 -Passthru -SourcePath 'F:\2012R
      2x64.ISO' -VHDPath 'E:\src5.vhd' -Edition 'ServerDataCenterEval'
      I get the following:
      WARN   : Transcription is already running.  No Convert-WindowsImage-specific transcript will be created.
      VERBOSE: isUserAdmin? True
      VERBOSE: isWindows8? True
      VERBOSE: Temporary VHD path is : E:\ab458354-4f5a-40fb-9dbc-84a7fbc3c25c.vhd
      INFO   : Opening ISO 2012R2x64.ISO...
      ERROR  : Cannot bind argument to parameter 'Path' because it is null.
      Long story short, somewhere around line 4000 is the line $SourcePath  = "$($driveLetter):\sources\install.wim".  Validatescript is failing on this variable.
      So I throw this in:
                      Write-Debug "Check the mount..."
                      Test-Path $(Resolve-Path "$($driveLetter):\sources\install.wim")
                      "What is going on...: $_"
      Resolve-Path : Cannot find drive. A drive with the name 'H' does not exist.
      Any tips?  I can browse to H: at the debug point.  No issues whatsoever.  From another PowerShell session I can see H:.  Perhaps I just need caffeine, but I'm stumped.
      Oh.  As if that's not strange enough... I can take the exact command line from my verbose output, run the convert-windowsimage.ps1 directly; after this, in the same session my function works.  This is quite weird.
      Will keep digging into this, but if anyone has any tips, they would be greatly appreciated!
    • Not worth the effort in finding the cause of this bug.  Guessing it's something odd with my environment / scope.  Worked around by launching Convert-WindowsImage in a new PowerShell process.
    • I can't seem to edit previous answers...
      This appears to be a bug specific to the PowerShell ISE (v4 in this case).  In another function where I'm doing a bunch of stuff, then simply mounting the VHD... I can't touch the VHD with PowerShell in that session after mounting it.  I can use .NET.  I can see it from another session and explorer.
      My solution is the same as above - I mount the VHD from another PowerShell process.
      The odd thing?  If I try to reproduce the issue in a function, or even in a function in a module, I don't get the same behavior.  But the other code is completely irrelevant (verbose output, various read / validation commands, etc.).... So I can't submit a bug on Connect.
  • error reguarding the last post
    2 Posts | Last post February 17, 2014
    • hi
      im having the same error as the lasts guy post but i did what you have suggusted : the command without any parameters' only the source path and it returns the same error.
      PS C:\Users\tala\Downloads>  .\Convert-WindowsImage.ps1 -SourcePath c:\TEST\install.wim
      Security warning
      Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
      computer. Do you want to run C:\Users\tala\Downloads\Convert-WindowsImage.ps1?
      [D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): r
      Windows(R) Image to Virtual Hard Disk Converter for Windows(R) 8
      Copyright (C) Microsoft Corporation.  All rights reserved.
      Version 6.3.9600.6.amd64fre.fbl_core1_hyp_dev(mikekol).140216-3000 Release to Web
      ERROR  : The variable cannot be validated because the value  is not a valid value for the Edition variable.
      INFO   : Log folder is C:\Users\tala\AppData\Local\Temp\Convert-WindowsImage\ee3581ec-eec9-4dc1-be19-7379f164e2f1
      INFO   : Closing Windows image...
      INFO   : Done.
    • Interesting. So, you don't have and ISO and run the script directly against the WIM, right?
  • Do you know why with QFE6 I can't make a Gen2 VHDX?
    3 Posts | Last post February 17, 2014
    • Hi,
      I have just tried to make a Gen2 VHDX of Windows Server 2012 R2 DTC but I get this error:
      BCDEDIT.EXE failed with code 1!
      If i check the log file i see this error:
      The boot configuration data store could not be opened.
      The system cannot find the file specified.
      I have tried with the previous version of Convert-WindowsImage.ps1 and I can make the Gen2 VHDX without problem.
    • Many thanks Mars, I was able to locate the issue and fix it quickly. Please download the updated version and give it a try.
    • ok the latest version fix the issue. Thank you !
121 - 130 of 154 Items