简体   繁体   中英

How to Add datadisk to arm virtual machine in azure WIth C# SDK?

my subscription i have 4 virtual machine each machine run on windows OS. i want add some data disk in each machine with using C# sdk

var computeClient = new Microsoft.Azure.Management.Compute.ComputeManagementClient(credentials) { SubscriptionId = subscriptionId };

this code get compute client

please go with below code.

var computeClient = new Microsoft.Azure.Management.Compute.ComputeManagementClient(credentials) { SubscriptionId = subscriptionId };

 var ObjVirtualMachines = computeClient.VirtualMachines.Get(<Resource Group Name>, <Virtual Machin Name>);

      try
        {
            ObjVirtualMachines.StorageProfile.DataDisks.Add(new DataDisk()
            {
                Name = "ArmDataDisk_0624",
                Vhd = new VirtualHardDisk("https://<StorageAccount Name>.blob.core.windows.net/vhds/<Name Of Data Disk>.vhd"),
                DiskSizeGB = 1023,
                Lun = 1,
                CreateOption="empty"
            });

            var newUpdatesVM = computeClient.VirtualMachines.CreateOrUpdate(<Resource Group Name>, ObjVirtualMachines.Name, ObjVirtualMachines);
        }
        catch (Exception exp)
        {

            throw exp;
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM