Weirdness with Convert-WindowsImage.ps1

I’ve encountered some oddities with using the Convert-WindowsImage.ps1 script found on the Microsoft Script Gallery:

Using my Win10 Enterprise desktop at home, I’m able to create bootable VHDX files from any OS and use them for VMs. If I run the exact same steps on my Surface 3 Pro (Win10 Pro), I am unable to create a bootable media.

Edit: Followup from Twitter exchange.
The error that occurs is when I try to start the VM with the created VHDX, the message is ‘Boot failure.’ This happens regardless of whether the image is Gen 1 (MBR) or Gen 2 (GPT).

Hyper-V: 10.0.10240.16431
Powershell: 5.0.10240.16384
Sample command:

Convert-WindowsImage -SourcePath C:\VMs\ISOs\en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso -VHDPath C:\VMs\ISOs\GM2012R2Core.vhdx -VHDFormat VHDX -VHDType Dynamic -Edition ServerStandardCore -VHDPartitionStyle MBR -UnattendPath C:\VMs\ISOs\unattend.xml -BCDinVHD VirtualMachine 

I can only speculate that there’s a difference between Pro and Enterprise, but at this point I’m grasping at straws. I’m wondering if anyone else has run in to this.

I have had a number of isues with Convert-WindowsImage. The version on the TechNet galary is old. the one on microsoft’s GitHub is more current but still a work in process.

Your example code uses VHDX and MBR, that is not a valid combination with but Convert-WindowsImage from TechNet lets you run that anyway.

I ended up writing my own Convert-WIM2VHD function. It’s part of WindowsImageTools on the PowerShell Galary.

Install-Module -Name WindowsImageTools

it’s also on GitHub GitHub - BladeFireLight/WindowsImageTools: PowerShell Tools creating and updating Windows Images

I have not had issues with it on Windows 10 so far. and I would be happy for some input.

As stated on Twitter, running your functions gets the same result. Here’s the info:


Convert-Wim2VHD -Path C:\VMS\VHDs\test2.vhdx -SourcePath C:\VMS\ISOs\en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso -DiskLayout UEFI -Dynamic -Index 3 -Size 50GB  -Force -Verbose -RecoveryImage

Verbose Log:

VERBOSE: [Convert-Wim2VHD] : Overwrite partitions inside [C:\VMS\VHDs\test2.vhdx] with content of [C:\VMS\ISOs\en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso]
VERBOSE: [Convert-Wim2VHD] : InitializeVHDPartitionParam
Name                           Value                                                                                                                                                                     
----                           -----                                                                                                                                                                     
Path                           C:\VMS\VHDs\test2.vhdx                                                                                                                                                    
Size                           53687091200                                                                                                                                                               
DiskLayout                     UEFI                                                                                                                                                                      
force                          True                                                                                                                                                                      
Dynamic                        True                                                                                                                                                                      
RecoveryImage                  True                                                                                                                                                                      

VERBOSE: [Convert-Wim2VHD] : SetVHDPartitionParam
Name                           Value                                                                                                                                                                     
----                           -----                                                                                                                                                                     
Confirm                        False                                                                                                                                                                     
Path                           C:\VMS\VHDs\test2.vhdx                                                                                                                                                    
Index                          3                                                                                                                                                                         
force                          True                                                                                                                                                                      
SourcePath                     C:\VMS\ISOs\en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso                                                                                                     

VERBOSE: [Convert-Wim2VHD] : ParametersToPass
Name                           Value                                                                                                                                                                     
----                           -----                                                                                                                                                                     
Verbose                        True                                                                                                                                                                      

VERBOSE: [Initialize-VHDPartition] Create partition structure for Bootable vhd(x) on [C:\VMS\VHDs\test2.vhdx]
VERBOSE: [Initialize-VHDPartition] Validating : Dislayout [UEFI] Setting Format to VHDX
VERBOSE: [Initialize-VHDPartition] Validating : [.vhdx] like [.VHDX]
VERBOSE: [Initialize-VHDPartition] [test2.vhdx] : Creating
VERBOSE: [Initialize-VHDPartition] [test2.vhdx] : @vhdParms
Name                           Value                                                                                                                                                                     
----                           -----                                                                                                                                                                     
Path                           C:\VMS\VHDs\test2.vhdx                                                                                                                                                    
SizeBytes                      53687091200                                                                                                                                                               
Dynamic                        True                                                                                                                                                                      
ErrorAction                    Stop                                                                                                                                                                      

VERBOSE: [Initialize-VHDPartition] [test2.vhdx] : Mounting disk image
VERBOSE: [Initialize-VHDPartition] [test2.vhdx] : Initializing disk [1] as GPT
VERBOSE: [Initialize-VHDPartition] [test2.vhdx] : Clearing disk partitions to start all over
VERBOSE: [Initialize-VHDPartition] [test2.vhdx] : Recovery tools : Creating partition of [314572800] bytes
VERBOSE: [Initialize-VHDPartition] [test2.vhdx] : Recovery tools : Formatting NTFS
VERBOSE: [Initialize-VHDPartition] [test2.vhdx] : EFI system : Creating partition of [209715200] bytes
VERBOSE: [Initialize-VHDPartition] [test2.vhdx] : EFI system : Formatting FAT32
VERBOSE: [Initialize-VHDPartition] [test2.vhdx] : EFI system : Setting system partition as ESP
VERBOSE: [Initialize-VHDPartition] [test2.vhdx] : MSR : Creating partition of [134217728] bytes
VERBOSE: [Initialize-VHDPartition] [test2.vhdx] : Windows : Creating partition of [36920360960] bytes
VERBOSE: [Initialize-VHDPartition] [test2.vhdx] : Windows : Formatting volume NTFS
VERBOSE: [Initialize-VHDPartition] [test2.vhdx] : Recovery Image : Creating partition using remaing free space
VERBOSE: [Initialize-VHDPartition] [test2.vhdx] : Recovery Image : Formatting volume NTFS
VERBOSE: [Initialize-VHDPartition] [test2.vhdx] : Dismounting disk image
VERBOSE: [Set-VHDPartition] : Overwrite partitions inside [C:\VMS\VHDs\test2.vhdx] with content of [C:\VMS\ISOs\en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso]
VERBOSE: [Set-VHDPartition] : Opening ISO [en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso]
VERBOSE: [Set-VHDPartition] : Looking for D:\sources\install.wim
VERBOSE: [Set-VHDPartition] [test2.vhdx] : Mounting disk image [C:\VMS\VHDs\test2.vhdx]
VERBOSE: [Set-VHDPartition] [test2.vhdx] : Munted as disknumber [1]
VERBOSE: [Set-VHDPartition] [test2.vhdx] : Partition Table
PartitionNumber DriveLetter        Size Type    
--------------- -----------        ---- ----    
              1           G   314572800 Recovery
              2           H   209715200 System  
              3               134217728 Reserved
              4           I 36920360960 Basic   
              5           J 16106127360 Recovery

VERBOSE: [Set-VHDPartition] [test2.vhdx] Recovery Image Partition [5] : copying [D:\sources\install.wim] to [J:\Recovery\install.wim]
VERBOSE: [Set-VHDPartition] [test2.vhdx] Windows Partition [4] : Applying image from [D:\sources\install.wim] to [I:\] using Index [3]
VERBOSE: Dism PowerShell Cmdlets Version
VERBOSE: [Set-VHDPartition] [test2.vhdx] System Partition [2] : Running [I:\Windows\System32\bcdboot.exe] -> I:\Windows /s H: /v /f UEFI
VERBOSE: [Run-Executable] : Running [bcdboot.exe] [I:\Windows /s H: /v /f UEFI]
Name                           Value                                                                                                                                                                     
----                           -----                                                                                                                                                                     
PassThru                       True                                                                                                                                                                      
FilePath                       bcdboot.exe                                                                                                                                                               
ArgumentList                   {I:\Windows, /s H:, /v, /f UEFI}                                                                                                                                          
RedirectStandardError          C:\Users\Mike\AppData\Local\Temp\bcdboot.exe-StandardError.txt                                                                                                            
NoNewWindow                    True                                                                                                                                                                      
Wait                           True                                                                                                                                                                      
RedirectStandardOutput         C:\Users\Mike\AppData\Local\Temp\bcdboot.exe-StandardOutput.txt                                                                                                           

VERBOSE: [Run-Executable] : Return code was [0]
VERBOSE: [Set-VHDPartition] [test2.vhdx] Recovery Tools Partition [1] : []
VERBOSE: [Set-VHDPartition] [test2.vhdx] Recovery Tools Partition [1] : Creating Recovery\WindowsRE folder [G:\Recovery\WindowsRE]
VERBOSE: [Set-VHDPartition] [test2.vhdx] Recovery Tools Partition [1] : Copying [I:\Windows\System32\recovery\winre.wim] to [G:\Recovery\WindowsRE]
VERBOSE: [Set-VHDPartition] [test2.vhdx] : Removing Drive letters
VERBOSE: [Set-VHDPartition] [test2.vhdx] : Dismounting
VERBOSE: [Set-VHDPartition] [test2.vhdx] : Finished

VHDX validation:

Get-VMHardDiskDrive Test2 | Select VMName,Controller*,DiskNumber,Path,@{Name="TestPath";Expression={$_ | Test-Path}}

VMName             : Test2
ControllerLocation : 0
ControllerNumber   : 0
ControllerType     : SCSI
DiskNumber         : 
Path               : C:\vms\VHDs\test2.vhdx
TestPath           : True

I’ll test with a Win10 ISO later tonight.

That is odd I just ran the same command and had no problems.
Have you tried a manual install from the ISO to make sure it’s good?

ISO is valid, just ran an install from it to a blank VM.

Have you tried this on another computer?

also give the scripts here a try. Jeff uses the files from inside the new VHDX to set the boot config. so the version always matches.

As stated in the original post, I can run the same script(s) with the same ISOs on my Win10 Enterprise desktop and home and make bootable VHDXs files. In fact, I’ve copied these files to my Surface and they work fine there as well. This is what I’m currently using for getting GM images for my Surface VMs.

If this is just Win10 on the Surface. sounds like an interesting bug with the underlying PowerShell and DISM function.