RSS

Monthly Archives: October 2015

Leveraging PowerShell to add multiple empty disks to Azure virtual machines

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 https://msdn.microsoft.com/nl-nl/library/azure/dn495298.aspx

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 https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-size-specs

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: https://msdn.microsoft.com/nl-nl/library/azure/dn495298.aspx
#

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

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.

disks

Feel free to try this yourself…

 

Advertisements
 
Leave a comment

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

 
 
Steve Thompson [MVP]

The automation specialist

Boudewijn Plomp

Cloud and related stuff...

Anything about IT

by Alex Verboon

MDTGuy.WordPress.com

Deployment Made Simple

Modern Workplace

Azure, Hybrid Identity & Enterprise Mobility + Security

Daan Weda

This WordPress.com 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