Hi @Dharshan M ,
Thanks for contacting Microsoft Q&A platform.
Below is the corrected code for you.
Console.WriteLine($"Creating a new VM using {captureimage}...");
var newVM = azure.VirtualMachines.Define(vmName)
.WithRegion(capturedImage.Location)
.WithExistingResourceGroup(resource)
.WithExistingPrimaryNetworkInterface(nic)
.WithWindowsCustomImage(capturedImage.Id)
.WithAdminUsername(adminUsername)
.WithAdminPassword(adminPassword)
.WithComputerName(vmName)
.WithSize(VirtualMachineSizeTypes.StandardD2sV3)
.Create();
var updatedVM = azure.VirtualMachines.GetById(newVM.Id)
.Update()
.WithTrustedLaunch(true) // Set Trusted Launch property
.Apply();
I added the missing method .WithTrustedLaunch(true)
to set the Trusted Launch property for the updated virtual machine.
If you encounter any issues or have specific requirements, consult the Azure SDK for .NET documentation for the correct methods and properties: https://docs.microsoft.com/en-us/dotnet/api/overview/azure/
Hope this helps you.