-1

I want to resize my os disk space but getting "Disk resizing is allowed only when creating a VM or when the VM is deallocated."

Microsoft.Azure.Management.ResourceManager.Fluent.Core.RestClient restClient = GetRestClient(requestObject);
            var computeClient = new ComputeManagementClient(restClient) { SubscriptionId = requestObject.SubscriptionId };
            var ObjVirtualMachines = computeClient.VirtualMachines.GetAsync(requestObject.ResourceGroupName, requestObject.VirtualMachineName, null, new System.Threading.CancellationToken()).Result;
            var disktodetach = ObjVirtualMachines.StorageProfile.OsDisk;
            ObjVirtualMachines.StorageProfile.OsDisk.DiskSizeGB = requestObject.DiskSize;
            var newUpdateVM = computeClient.VirtualMachines.CreateOrUpdateAsync(requestObject.ResourceGroupName, requestObject.VirtualMachineName, ObjVirtualMachines).Result;
            resizeDisk = newUpdateVM.ProvisioningState;
DnyaneshSurya
  • 187
  • 1
  • 1
  • 14
  • Check this link [Microsoft docs](https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.management.compute.models.disk.disksizegb?view=azure-dotnet) – 1_bug Jul 28 '21 at 06:00

1 Answers1

0

Thank you 1_bug. Posting your suggestions as answer to help other community members.

you cannot Increase the disk size for a running VM. Rather you can increase the disk size of a VM by shutting down the VM and following the below code.

[Newtonsoft.Json.JsonProperty(PropertyName="properties.diskSizeGB")]
public int? DiskSizeGB { get; set; }

enter image description here

Before using the above code check weather your code includes creationData.creationoption field is empty.

for further information check Disk.DiskSizeGB Property

SaiSakethGuduru
  • 2,218
  • 1
  • 5
  • 15