Over a million developers have joined DZone.

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

· Cloud Zone

Build fast, scale big with MongoDB Atlas, a hosted service for the leading NoSQL database on AWS. Try it now! Brought to you in partnership with MongoDB.

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 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

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

    # Select Azure Storage Account
    $storageAccount =
        (Get-AzureStorageAccount).Label `
        | Out-GridView `
            -Title "Select Azure Storage Account" `
    Set-AzureSubscription `
        -SubscriptionName $subscription `
        -CurrentStorageAccountName $storageAccount

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

    # Select Data Disk to resize
    $disk =
        $vm `
        | Get-AzureDataDisk `
        | Out-GridView `
            -Title "Select a data disk to resize" `
    $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 `

    # 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

Now it's easier than ever to get started with MongoDB, the database that allows startups and enterprises alike to rapidly build planet-scale apps. Introducing MongoDB Atlas, the official hosted service for the database on AWS. Try it now! Brought to you in partnership with MongoDB.


Published at DZone with permission of Keith Mayer, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}