how to give the security type to the vm to trusted launch vm in csharp

Dharshan M 0 Reputation points
2023-11-24T05:25:09.09+00:00

i need to set the security type to trusted launch virtual machine while creating the virtual machine from the image is the code is correct give me clarity
thank you for the upcoming answers...

  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()
                                                     .(true)  // Set Trusted Launch property
                                                     .Apply();
Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,028 questions
{count} votes

1 answer

Sort by: Most helpful
  1. v-vvellanki-MSFT 4,920 Reputation points Microsoft External Staff
    2023-11-27T08:45:58.4+00:00

    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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.