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)
139,171 times
Add to favorites
Storage
6/19/2015
E-mail Twitter del.icio.us Digg Facebook
  • Running Cmdlet without specifying edition
    2 Posts | Last post February 16, 2014
    • Hey,
      
      Does anybody have a clue how to run the script without initializing Edition parameter?
      
      I mean, the help page reads as follows:
      
      ".\Convert-WindowsImage.ps1 -SourcePath D:\sources\install.wim  
      # Since no edition is being specified, the command will succeed if there is only one image in the specified WIM file. If there are multiple images, the command will fail and it will list the possible editions."
      
      I am running this command and can't get past specifying Edition:
      
      .\Convert-WindowsImage.ps1 -SourcePath F:\Backup\Images\image.wim -VHDFormat VHDX -VHDType Fixed -SizeBytes 4GB -WorkingDirectory "F:\Backup\Images\"
      
      $error returns:
      
      The variable cannot be validated because the value  is not a valid value for the Edition variable.
      At C:\Users\EH\Downloads\Convert-WindowsImage.ps1:4012 char:13
      +             $Edition   = $openWim.Images[0].ImageFlags
      +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : MetadataError: (:) [], ValidationMetadataException
          + FullyQualifiedErrorId : ValidateSetFailure
       
      Start-Transcript : This host does not support transcription.
      At C:\Users\EH\Downloads\Convert-WindowsImage.ps1:3219 char:21
      +             $null = Start-Transcript -Path (Join-Path $logFolder "Convert-Window ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : NotImplemented: (:) [Start-Transcript], PSNotSupportedException
          + FullyQualifiedErrorId : NotSupported,Microsoft.PowerShell.Commands.StartTranscriptCommand
      
      What could be the problem. I am trying to convert a WIM that was made from a USB stick with a Windows 8.1 setup files on it.
      
      Any clue on what I am missing here?
      
      Thanks,
      EH
      
      P.S. My apologies for not letting Mike know of the error regarding the issue I was facing back 2 yrs ago. Looks like I missed his response, how unpleasant of me.
    • When you omit the -Edition switch, you're not supposed to produce any real VHD(x). As the help says, you're supposed to find out the names of the images inside the ISO. Thus, there's no need to specify any further parameters like -VHDFormat or -VHDType. Just use the -SourcePath alone.
      
      
      
      Does this make more sense now?
      
      
       .\Convert-WindowsImage.ps1 -SourcePath "\\Server.Domain.Com\Share\SW_DVD9_Windows_Svr_Std_and_DataCtr_2012_R2_64Bit_English_-2_Core_MLF_X19-31419.ISO" 
      
      Windows(R) Image to Virtual Hard Disk Converter for Windows(R) 8
      Copyright (C) Microsoft Corporation.  All rights reserved.
      Version 6.3.9600.5.amd64fre.fbl_core1_hyp_dev(mikekol).140216-2000 Release to Web
      
      WARN   : Transcription is already running.  No Convert-WindowsImage-specific transcript will be created.
      INFO   : Copying ISO SW_DVD9_Windows_Svr_Std_and_DataCtr_2012_R2_64Bit_English_-2_Core_MLF_X19-31419.ISO to temp folder...
      INFO   : Opening ISO SW_DVD9_Windows_Svr_Std_and_DataCtr_2012_R2_64Bit_English_-2_Core_MLF_X19-31419.ISO...
      INFO   : Looking for D:\sources\install.wim...
      ERROR  : You must specify an Edition or SKU index, since the WIM has more than one image.
      ERROR  : Valid edition names are:
      ERROR  :   ServerStandardCore
      ERROR  :   ServerStandard
      ERROR  :   ServerDataCenterCore
      ERROR  :   ServerDataCenter
      ERROR  : ScriptHalted
      INFO   : Log folder is C:\Users\USER-P~1\AppData\Local\Temp\8\Convert-WindowsImage\81df33af-fdd4-43f3-8472-814775c58232
      INFO   : Closing Windows image...
      INFO   : Closing ISO...
      INFO   : Done.
      
      
      Thanks,
      --Artem
  • Convert .iso to VHDX issues
    4 Posts | Last post February 16, 2014
    • Hi Pronichkin,
      
      I am trying to convert a customized Windows Server 2012 esssentials R2 .iso image to VHDX but when I run the command below as instructed by Microsoft in the ADK kit (http://technet.microsoft.com/en-us/library/dn293253.aspx)I get an error. 
      
      Initialize-Disk : Invalid property
      At C:\scripts\Convert-WindowsImage.ps1:4077 char:13
      +             Initialize-Disk -Number $openVhd.DiskIndex -PartitionStyle MBR
      +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : MetadataError: (MSFT_Disk:ROOT/Microsoft/Windows
         /Storage/MSFT_Disk) [Initialize-Disk], CimException
          + FullyQualifiedErrorId : HRESULT 0x80041031,Initialize-Disk
      INFO   : Disk initialized with MBR...
      Get-Disk : Invalid property
      At C:\scripts\Convert-WindowsImage.ps1:4084 char:22
      +         $disk      = Get-Disk -Number $openVhd.DiskIndex
      +                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : MetadataError: (MSFT_Disk:ROOT/Microsoft/Windows
         /Storage/MSFT_Disk) [Get-Disk], CimException
          + FullyQualifiedErrorId : HRESULT 0x80041031,Get-Disk
      New-Partition : Invalid property
      At C:\scripts\Convert-WindowsImage.ps1:4087 char:32
      +             $partition       = New-Partition -DiskNumber $openVhd.DiskIndex
      -Siz ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      ~~~
          + CategoryInfo          : MetadataError: (MSFT_Disk:ROOT/Microsoft/Windows
         /Storage/MSFT_Disk) [New-Partition], CimException
          + FullyQualifiedErrorId : HRESULT 0x80041031,New-Partition
      INFO   : Disk partitioned...
      ERROR  : Cannot validate argument on parameter 'Partition'. The argument is null
      . Provide a valid value for the argument, and then try running the command again
      INFO   : Log folder is C:\Users\BLKDO_~1\AppData\Local\Temp\Convert-WindowsImage
      \b9a97d0d-72ff-48e0-8136-c5c3423b9cb7
      
      Best Regards,
      Abby
    • Hello Abby_Doc,
      
      can you please try the same steps with some other ISO image? This way we can ensure whether the issue is with your customized Essentials ISO of with your environment where you're running the script.
      
      
      Thank you,
      --Artem
    • Hi Pronichkin,
      
      I have managed to resolve the issue buy building using the different machine but the same ISO. I think there might be an issue with my current tech machine and will try a again once I do a rebuild.
      
      Best Regards,
      
      Abby_Doc
    • Thanks for letting us know you've figured it out!
  • Expanded Use of your Script
    2 Posts | Last post February 16, 2014
    • Thought you might get a kick out of this.  I leveraged your script as part of a solution to automatically build VHD templates with the free Hyper-V Server 2012 R2
      
      http://pronichkin.com/default.aspx
      
      
    • Thanks for the feedback! You're very welcome to share any findings.
  • Can Convert-WindowsImage convert a .WIM from Command Prompt's "recimg" on Windows 8.1?
    2 Posts | Last post January 27, 2014
    • Hi Folks,
      
      
      I have been trying to do this several times, including with the UI. The UI afforded a bit more info; it was complaining about the .WIM metadata:
      
      
      With PowerShell: 
      
      PS C:\Windows\system32> Convert-WindowsImage -SourcePath "E:\@.RefreshImage\2014-01-18\CustomRefresh.wim" -VHDPath "D:\Hyper-V\Virtual Hard Disks\W 8.1 Pro 1.vhdx" -Edition Professional -VHDFormat VHDX -Verbose -db
      
      
      **********************
       Windows PowerShell transcript start
       Start time: 20140121092326
       Username : TammyLacey\Crysta T Lacey 
       Machine : TAMMYLACEY (Microsoft Windows NT 6.3.9600.0) 
       **********************
       DEBUG:
      
      
      
      
      
      >>>>>>>>>>>>>>>>>> I have the rest of the DEBUG your interested but it is over 4000 lines<<<<<<<<<<<<<<<
      
      
       VERBOSE: isUserAdmin? True
       VERBOSE: isWindows8? True
       VERBOSE: Temporary VHDX path is : D:\Hyper-V\Virtual Hard Disks\e53a41bc-6a5e-4d85-9b77-33d0e48b40b8.vhdx
       ERROR : You cannot call a method on a null-valued expression.
       INFO : Log folder is C:\Users\CRYSTA~1\AppData\Local\Temp\Convert-WindowsImage\e53a41bc-6a5e-4d85-9b77-33d0e48b40b8
       INFO : Closing Windows image...
       INFO : Done.
       **********************
       Windows PowerShell transcript end
       End time: 20140121093332
       **********************
      
      
      Thank You,
      
      
      
      Best Regards,
      
      
      Crysta
    • Hi Crysta,
      
      are you using the same source ISO image all the time? Can you please try using some other known good image?
      
      
      Thanks,
      --Artem
  • Wim GUI issue
    2 Posts | Last post January 06, 2014
    • Hi Pronichkin,
      thanks for this great utility. I was attempting to test this using the new ShowUI function and am stumbling across this message. 
      PS D:\Downloads\Wim2VHD> .\Convert-WindowsImage.ps1 -showui
      
      
      INFO   : Launching UI...
      INFO   : Opening ISO en_windows_7_enterprise_with_sp1_x64_dvd_u_677651.iso...
      INFO   : Looking for K:\sources\install.wim...
      INFO   : Scanning WIM metadata...
      INFO   : Image 1 selected (Enterprise)...
      INFO   : Creating sparse disk...
      INFO   : Attaching VHD...
      INFO   : Disk initialized with MBR...
      INFO   : Disk partitioned...
      Format-Volume : One or more parameter values passed to the method were invalid.
      At D:\Downloads\Wim2VHD\Convert-WindowsImage.ps1:4096 char:26
      +             $volume    = Format-Volume -Partition $partition -FileSystem NTFS -F ...
      +                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidArgument: (MSFT_Volume (Ob...3-826e-b876...):ROOT/Microsoft/...age/MSFT_Volume) [
         Format-Volume], CimException
          + FullyQualifiedErrorId : MI RESULT 4,Format-Volume
      
      INFO   : Volume formatted...
      INFO   : Access path (L:\) has been assigned...
      INFO   : Applying image to VHD. This could take a while...
      ERROR  : Exception calling "Apply" with "1" argument(s): "The WIM cannot be applied because the specified directory was
      not found."
      INFO   : Log folder is C:\Users\tony\AppData\Local\T
      
      I have copied my ISO and the creation of the VHD file is in the same directory as the PS script so everything is being read from and created to the same directory on my Win8.1 workstation. Any ideas?
      Thank You
    • Hi Tony, 
      
      can you please try the same set of options why using command-line syntax? This would help to narrow down the root cause.
      
      
      Thanks,
      --Artem
  • Version 2 VM Disk
    7 Posts | Last post December 26, 2013
    • Is there a way to createt a vhdx that we can used on the new Version 2 VM Format on Server 2012 R2. After Creating the vhdx and put to the SCSI Device the Boot process find no UEFI Harddisk.
    • same here, after mounting the vhdx (2012R2)  to a new GEN 2 VM the disk is not found and Hyper-V will end in pxe search ! 
    • Generation 2 VMs use UEFI to boot the system. Windows install on UEFI requires a specific partition structure: http://technet.microsoft.com/en-us/library/hh825702.aspx. You could take a look at this conversion script from Gen1 to Gen2: http://code.msdn.microsoft.com/Convert-VMGeneration-81ddafa2 to get you started.
    • conversion script is great, however do you plan to support generation 2 VMs in convert-windowsimage.ps1? 
      
      we are using your script to automate vm provisioning, and conversion script would introduce another (complicated) step in our script, as we would have to delete the original vm after conversion etc. it would be perfect to be able to simply create a gen2 VM within a single script.
    • Folks,
      
      Generation 2 support is coming in next few weeks. Please excuse any delay and thank you for your patience.
    • Hello! Thank you for your patience. The update which now supports Generation 2 VMs is just published. Please try it out! Any feedback is highly welcomed.
    • I still haven't tested it, but big THANK YOU from all of us who have been waiting for generation 2 support :-)
  • Could not get the BootMgr object from the Virtual Disks BCDStore
    5 Posts | Last post December 25, 2013
    • I'm getting the following error and the log files aren't much use.  This happed using either the command line or the GUI.  Any ideas?
      
      - Mark
      ----------
      PS C:\Software\System Center PDT> .\Convert-WindowsImage.ps1 -SourcePath C:\Software\en_windows_server_2012_x64_dvd_915478.iso -VHDFormat VHDX -SizeBytes 128GB -VHDPath .\xxx.vhdx -Edition serverdatacenter -DiskType dynamic
      
      Windows(R) Image to Virtual Hard Disk Converter for Windows(R) 8
      Copyright (C) Microsoft Corporation.  All rights reserved.
      Version 6.2.8424.1.amd64fre.fbl_core1_hyp_dev(mikekol).120517-1616 Release Preview
      
      INFO   : Opening ISO en_windows_server_2012_x64_dvd_915478.iso...
      INFO   : Looking for E:\sources\install.wim...
      INFO   : Image 4 selected (ServerDataCenter)...
      INFO   : Creating sparse disk...
      INFO   : Attaching VHDX...
      INFO   : Disk initialized...
      INFO   : Disk partitioned...
      INFO   : Volume formatted...
      INFO   : Access path (F:\) has been assigned...
      INFO   : Applying image to VHDX.  This could take a while...
      INFO   : Signing disk...
      INFO   : Image applied.  Making image bootable...
      INFO   : Opening F:\boot\bcd for configuration...
      ERROR  : Could not get the BootMgr object from the Virtual Disks BCDStore.
      INFO   : Log folder is C:\Users\BIGKAH~1\AppData\Local\Temp\2\Convert-WindowsImage\c8b65de8-fbdf-4ad9-a1b7-090f281d0b64
      INFO   : Closing Windows image...
      INFO   : Closing VHDX...
      INFO   : Closing ISO...
      INFO   : Done.
    • Additional information: The actual problem is the bootMgr object (at line 2905 in the version I downloaded yesterday) is not being correctly created.  It appears this is a result of a StoreFilePath not being what is expected/wanted.  If I move the file "F:\boot\bcd" to the local disk (C:) and then manually execute the command in PowerShell, it succeeds.  But when I use the same command for the file on the ISO "device" it fails.  So there appears to be something about where the file is located which is causing problems.
      
      Not sure where to go from here.
    • I don't see this issue when creating the Server 2012 vhdx on a system that has booted from BIOS but I do get the exact same error if I try to create the vhdx on a system that has booted from UEFI.
      \boot folder doesn't get copied from the iso to the vhdx on a UEFI system so the script can't find boot\bcd.
      
    • Here's the fix(es):
      This is a spelling error but probably isn't the problem here. Around line 2782 change
      [ValidateScript({ ($_ -eq $PARTITION_STYLE_MBR) -or ($_ -eq $PARTITON_STYLE_GPT) })]
      
      to
      
      [ValidateScript({ ($_ -eq $PARTITION_STYLE_MBR) -or ($_ -eq $PARTITION_STYLE_GPT) })]
      Missing an 'I' in the second PARTITION
      
      This resolved the error we were getting.  Around line 4055 change
      $bcdBootArgs = @(
          "$($drive)Windows",    # Path to the \Windows on the VHD
          "/s $drive",           # Specifies the volume letter of the drive to create the \BOOT folder on.
          "/v"                   # Enabled verbose logging.
                  )
      to
      
      $bcdBootArgs = @(
          "$($drive)Windows",    # Path to the \Windows on the VHD
          "/s $drive /f BIOS",   # Specifies the volume letter of the drive to create the \BOOT folder on.
          "/v"                   # Enabled verbose logging.
      
      Added /f BIOS to the line /s $drive
                  )
      
    • Hello! Thank you for your patience. The update published today includes the fix for this issue. (Also many new features like support for Generation 2 VMs). Please try it out! Any feedback is highly welcomed.
  • Gen 2 VMs
    2 Posts | Last post December 25, 2013
    • First off thankyou for an excellent script.
      
      Just wondering how support for Generation 2 VMs is coming along?
      
      Thanks,
      
      David
    • Hello! Thank you for your patience. The update which now supports Generation 2 VMs is just published. Please try it out! Any feedback is highly welcomed.
  • Error Transcript for the Failed WIM Metadata Reading Operation. Part Two
    6 Posts | Last post November 27, 2013
    • Unable to load WIM metadata!
      At C:\Users\EH\Downloads\Convert-WindowsImage.ps1:3345 char:25
      +                         throw "Unable to load WIM metadata!"
      +                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : OperationStopped: (Unable to load WIM metadata!:String) [], RuntimeException
          + FullyQualifiedErrorId : Unable to load WIM metadata!
       
      Exception calling "Add" with "1" argument(s): "Value cannot be null.
      Parameter name: item"
      At C:\Users\EH\Downloads\Convert-WindowsImage.ps1:3339 char:54
      +                             $tempOpenWim.Images | %{ $cmbSkuList.Items.Add($_.Im ...
      +                                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
          + FullyQualifiedErrorId : ArgumentNullException
       
      Start-Transcript : This host does not support transcription.
      At C:\Users\EH\Downloads\Convert-WindowsImage.ps1:3167 char:21
      +             $null = Start-Transcript -Path (Join-Path $logFolder "Convert-Window ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : NotImplemented: (:) [Start-Transcript], PSNotSupportedException
          + FullyQualifiedErrorId : NotSupported,Microsoft.PowerShell.Commands.StartTranscriptCommand
      
      ----END----
      
      Thank you for your script!
      
      I'll be waiting thrilled for the resolution.
    • Hi Exotic - sorry that I haven't gotten back to you for a while.
      
      I wanted to give you a quick update:
      As of about a month ago, I no longer work for Microsoft, so I no longer have access to Windows 8 bits (which is to say that I don't have access to anything newer than the Release Preview).
      
      On top of that, ownership of the script is now murky at best. I wrote the script in my personal time, but I released it through Microsoft because it seemed like the right thing to do at the time.  In order to continue maintaining it myself, I may need to fork the code and work exclusively with the fork. I'm still trying to get all of this sorted out.
      
      In the meanwhile, can you tell me a little bit about the installation media that you're using?  Is this a custom WIM, or is it one that was created and shipped by Microsoft?
    • Hello, Mike!
      
      I am very sorry to have missed your question and I must express many thanks for your help.
      That was a custom WIM Image of a machine running Windows Server 2008 R2 created using ImageX.
      
      Thank you.
    • Colleagues, you have to put additional metadata in to WIM file:<FLAGS>Professional</FLAGS>
      Just use http://www.autoitscript.com/site/autoit-tools/gimagex/ and on 'Change' tab use SKU Flag drop down menu.
      
      
    • Hmm, script doesn't work on Win 2012. Many error messages and more. GImageX is from 2009
    • As of about a week ago GImageX has been updated to compatibility with Windows 8.1. I used it to add the Enterprise FLAG to a custom Windows 7 wim file without a problem.
  • Problem converting linux iso to vhd
    1 Posts | Last post June 18, 2013
    • I'm trying to use this script to convert an arch linux iso to a bootable VHD, and I keep getting the same error in powershell, no matter what I try 
       
      Cannot bind argument to parameter 'Path' because it is null.
      
      I have the .ps1 and .iso file saved in the folder C:\arch, and the iso saved as arch.iso
      I've tried changing directories, renaming the folder and iso file, but nothing seems to work.
131 - 140 of 154 Items