Add disks to VMs in Azure

Sometimes you have the need to add additional disks to VM’s in Azure.. and if you happen to manage a big farm of servers and all servers need to have additional disks, you find yourself in the portal a lot.. or in Powershell hacking your way through variables and collections..

This script will help you adding one or multiple disks to a single VM, all VM’s in a ResourceGroup or all VM’s in a ResourceGroup starting with a particular nameThe powershell script can be found here -> diskadd-toVM <- and has the following command options:

The script has the following parameters:

-ResourceGroup [mandatory]

Provide the name of the resource group containing your VM(s)

     -SizeinGB[Mandatory]

Size of disks to add

     -Cache[Mandatory]

Defines the cache for the disk [none/readonly/readwrite]

-TargetVM [optional]

Specify a single VM to add disks to [if not specified and VMPrefix is not specified script will run against all VM’s in a ResGroup]

     -VMPrefix[optional]

Used to add disks to all VM’s starting with this name (for example “ClusterNode”) [if not specified and TargetVM is not specified script will run against all VM’s in a ResGroup]

     -MaxDisks[optional] [default = $false]

If specified, will add multiple disks to the max entered here (eg all servers will have <12 disks after running this with 12)

     -MaxDisks[optional] [default = $false]

$false : will not create a log file
$true : creates a logfile in form of: AzureCleanLog-19-4-17-10.48.27.log in the current directory

So your initial commands are:

C:\PS>DiskAdd-toVM.ps1 -ResourceGroup ‘MyResourceGroup’ -VMTarget “VMName” -SizeInGB 1023 -Cache none
<Will add a single 1TB disk to VMName VM>
C:\PS>DiskAdd-toVM.ps1 -ResourceGroup ‘MyResourceGroup’ -SizeInGB 1023 -Cache none
<Will add a single 1TB disk to ALL VM”s in Resource Group MyResourceGroup>
C:\PS>DiskAdd-toVM.ps1 -ResourceGroup ‘MyResourceGroup’ -VMPrefix ‘MyClusterNode’-SizeInGB 1023 -Cache none
<Will add a single 1TB disk to ALL VM”s where the name starts with ‘MyClusterNode’ in Resource Group MyResourceGroup>
C:\PS>DiskAdd-toVM.ps1 -ResourceGroup ‘MyResourceGroup’ -VMPrefix ‘MyClusterNode’-SizeInGB 1023 -Cache none -MaxDisks 10
<Will ensure all VM”s where the name starts with ‘MyClusterNode’ in Resource Group MyResourceGroup will have at least 10 disks, new disks added will be 1Tb in size>
New disks will be created in the same storage account as the Operating System disk for the VM. There is no support yet for Managed disks.