Leveraging PowerShell to add multiple empty disks to Azure virtual machines

06 Oct

This post’s a quicky…

Adding disks is quite a straightforward action which can be achieved by a single PowerShell cmdlet: Get-AzureVM “myservice” -Name “MyVM” | Add-AzureDataDisk -CreateNew -DiskSizeInGB 128 -DiskLabel “main” -LUN 0 | Update-AzureVM

More information for this cmdlet is available at

Empty disks, with a maximum size of 1023 GB, have some limitations regarding maximum IOPS. On top of that, each Azure VM size allows a maximum amount of datadisks to be connected. An overview of these Azure VM sizes is available at

These disks can be added to storage pools to have one or more disks with to with bigger sizes.

I investigated how I could add 14 disks to an A4 sized Azure VM quickly. It’s quite easy to achieve with a .csv file and a loop. The script may look like this:

# Script name: add_disks_azurevm.ps1
# Purpose: Adds multiple empty datadisks to at least one Azure VM, uses .csv as input
# Author: Marc Westerink
# Reference:

Import-Module “C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Azure.psd1”

Import-Csv C:\temp\disks.csv | % {

Set-AzureSubscription -SubscriptionName $_.SubscriptionName -CurrentStorageAccountName $_.StorageAccountName
Get-AzureVM -ServiceName $_.ServiceName -Name $_.VMName | Add-AzureDataDisk -CreateNew -DiskSizeInGB $_.DiskSizeInGB -DiskLabel $_.DiskLabel -LUN $_.LUN | Update-AzureVM

The .csv file that delivers the required information can easily be edited in Excel. The script even allows switching to a different subscription and/or storage account which adds some flexibility. It doesn’t matter if the same subscription information is set multiple times.

After running this script I can see the disks are available in my Azure VM and use them to my needs.


Feel free to try this yourself…


Leave a comment

Posted by on 06/10/2015 in Azure, PowerShell


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Steve Thompson [MVP]

The automation specialist

Boudewijn Plomp

Cloud and related stuff...

Anything about IT

by Alex Verboon

Deployment Made Simple

Modern Workplace

Azure, Hybrid Identity & Enterprise Mobility + Security

Daan Weda

This site is all about System Center and PowerShell

IT And Management by Abheek

Microsoft certified Trainer -Abheek

Heading To The Clouds

by Marthijn van Rheenen

%d bloggers like this: