BenjaminArmstrong / Hyper-V-PowerShell

Scripts that primarily use the Hyper-V PowerShell interfaces driving virtual machines
MIT License
131 stars 47 forks source link

Convert-WindowsImage.ps1 broken on 1709 #38

Open pbolduc opened 6 years ago

pbolduc commented 6 years ago

Hi Ben, I know you do not support Convert-WindowsImage.ps1 from the TechNet Gallery. However, I am trying find out what changed from 1703 to 1709 of Windows 10 that breaks the image converter. Something changed in the API WimApplyImage from Wimgapi.dll

Any assistance you can provide would be appreciated.

This change breaks the vhdx creation in Hyper-V-PowerShell scripts on Windows 10.

I could try to modify to use the Convert-WindowsImage.ps1 from the NanoServerImageGenerator on Windows Server 2016 disk, but I am unsure about the licensing of that script. It says:

Use of this sample source code is subject to the terms of the Microsoft
license agreement under which you licensed this sample source code.

I know there is someone at Microsoft knows what changed with this API in 1709.

Here is the error you get when running the image factory on Windows 10 Pro 1709.

Exception calling "Apply" with "1" argument(s): "The directory or file cannot be created"

full log:

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   : Opening ISO en_windows_server_2016_x64_dvd_9327751.iso...
INFO   : Looking for E:\sources\install.wim...

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 (F:\) has been assigned to the System Volume...
INFO   : Access path (\\?\Volume{4a8daf5b-08cc-499f-ba80-456d6f68cb38}\) has been assigned to the Boot Volume...
INFO   : Applying image to VHDX. This could take a while...
ERROR  : Exception calling "Apply" with "1" argument(s): "The directory or file cannot be created"
INFO   : Log folder is C:\Users\Phil\AppData\Local\Temp\Convert-WindowsImage\ce2f5e7c-e52a-4e13-b296-fff0fa6e64af

INFO   : Closing Windows image...
INFO   : Closing VHDX...
INFO   : Closing ISO...
INFO   : Done.
pbolduc commented 6 years ago

I looked into this a bit more. The Nano Server version uses cmdlet Expand-WindowsImage from the DISM module. I proposed to Artem Pronichkin that a check for for the existence of this cmdlet could be the fix. Use it if found (Win 8.1 and beyond) or try old method (Win 7).

zelenin commented 6 years ago

https://github.com/nerdile/convert-windowsimage