Share via


Resizing Data Disks in the Cloud on Microsoft Azure with Windows PowerShell

Resizing existing Azure VM data disks just got a whole lot easier with the introduction of an enhanced Update-AzureDisk PowerShell cmdlet in the latest version of the Azure PowerShell module.

Click to zoom ...

In this article, I’ll step through the process of using this new cmdlet to increase the size of an existing data disk on an Azure virtual machine.

Getting started …

To follow along with the steps in this article, you’ll need an active Azure subscription and the latest version of the Azure PowerShell module, which is version 0.8.15.1 as of this article’s date.

In order to resize an existing VM data disk, you’ll also need to have at least one VM provisioned with a data disk attached.

Resize Azure Data Disks via Azure PowerShell Script

Below, I’ve included a sample Azure PowerShell snippet that you can incorporate into your own script for increasing the size of existing Azure VM data disks.

# Authenticate to Azure Account

Add-AzureAccount

# Select Azure Subscription

$subscription =
(Get-AzureSubscription).SubscriptionName `
| Out-GridView `
-Title "Select Azure Subscription" `
-PassThru

Select-AzureSubscription `
-SubscriptionName $subscription `
-Current

# Select Azure Storage Account

$storageAccount =
(Get-AzureStorageAccount).Label `
| Out-GridView `
-Title "Select Azure Storage Account" `
-PassThru

Set-AzureSubscription `
-SubscriptionName $subscription `
-CurrentStorageAccountName $storageAccount

# Select Azure VM

$vm =
Get-AzureVM `
| Out-GridView `
-Title "Select a VM ..." `
-PassThru

# Select Data Disk to resize

$disk =
$vm `
| Get-AzureDataDisk `
| Out-GridView `
-Title "Select a data disk to resize" `
-PassThru

$diskName = $disk.DiskName

# Specify new Data Disk size – must be larger than current size

do {

$size =
Read-Host `
-Prompt "New size in GB"

}

until ( $size -gt $disk.LogicalDiskSizeInGB )

# Stop and Deallocate VM prior to resizing data disk

$vm `
| Stop-AzureVM `
-Force

# Resize Data Disk to Larger Size

Update-AzureDisk `
-Label "$diskName" `
-DiskName "$diskName" `
-ResizedSizeInGB $size

# Start VM

$vm | Start-AzureVM

Extending the Data Volume

After updating the data disk to a larger size, you’ll need to extend the file system volume on that data disk to be able to access the additional space.  You can easily perform this task using Server Manager from within a Remote Desktop connection to the Azure VM.

Click to zoom ...
Extending Existing Data Volume on a Resized Data Disk