Skip to content

Optimization: Modernize Create-ImageVirtualDisk using native PowerShell cmdlets#416

Open
msancaktutan wants to merge 1 commit intocloudbase:masterfrom
msancaktutan:optimize-disk-creation
Open

Optimization: Modernize Create-ImageVirtualDisk using native PowerShell cmdlets#416
msancaktutan wants to merge 1 commit intocloudbase:masterfrom
msancaktutan:optimize-disk-creation

Conversation

@msancaktutan
Copy link

Description:
This PR optimizes the Create-ImageVirtualDisk function to improve reliability, performance, and modernization of the codebase.

Changes:

  • Replaced Regex parsing: Switched from parsing physical drive strings (which can be risky on different hardware) to using Get-DiskImage | Get-Disk for 100% accurate disk detection.
  • Removed external dependency: Replaced the legacy format.com call with the native Format-Volume PowerShell cmdlet for faster execution and better error handling.
  • Added Retry Logic: Implemented Execute-Retry during disk detection to handle potential OS delays when attaching VHDs.
  • Code Cleanup: Improved logging and resource cleanup (closing handles).

Tested on Windows Server 2016/2019/2022/2025

@ader1990
Copy link
Member

Hello,

Thank you for the contribution.
Can you please specify on which Windows Server builds ids you tested on?

Thanks.

@msancaktutan
Copy link
Author

Hello,

I tested on the latest builds of Windows Server 2016, 2019, 2022, and 2025, which I downloaded from the official website.

@ader1990
Copy link
Member

Hello,

I tested on the latest builds of Windows Server 2016, 2019, 2022, and 2025, which I downloaded from the official website.

Oh, you mean that you created Windows image for Windows Server 2016, 2019, 2022, and 2025? or you tested that the code still works on Windows Server 2016, 2019, 2022, and 2025 Hyper-V hosts?

@msancaktutan
Copy link
Author

I used Windows 11 as my host machine to run the script, and successfully created the guest images for Windows Server 2016, 2019, 2022, and 2025.

Windows 11 Pro 25H2
OS Build: 26200.7840

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants