'Azure SDK C# - Create VM(StandardB2s) from Image with specified disk type (Standard HDD)

I am using the Azure SDK in a C# .NET application to create Azure VMs StandardB2s on demand.

At the moment, the VMs are created using SSD disk, but I would like to use Standard HDD instead.

However, I can't find anything in the documentation how to configure the OS disk size during the creation.

Please find my current implementation below :

        .WithRegion(region)
        .WithExistingResourceGroup(resourceGroupName)
        .WithExistingPrimaryNetworkInterface(networkInterface)
        .WithLatestWindowsImage("MicrosoftWindowsServer", "WindowsServer", "2022-datacenter-azure-edition")
        .WithAdminUsername(adminUser)
        .WithAdminPassword(adminPassword)
        .WithUnmanagedDisks()
        .WithComputerName(vmName)
        .WithOSDiskSizeInGB(128)
        .WithOSDiskName(vmDiskName)
        .WithSize(VirtualMachineSizeTypes.StandardB2s)
        .Create();


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source