Adding disk to Azure VM using Resource Manager-PowerShell

Posted: December 2, 2016 in Azure

In previous post we added new disk to VM using Azure Portal,in this one we’ll do exactly the same think using PowerShell only:

#Specify your VM Name
$vmName="myazurevm"
#Specify Resource Group
$rgName = "rg"
#Specify Storage account name
$saName="mystorageaccount112016"
#Export storage account into variable
$storageAcc=Get-AzureRmStorageAccount -ResourceGroupName $rgName -Name  $saName
#Pulls the VM info
$vmdiskadd=Get-AzurermVM -ResourceGroupName $rgname -Name $vmname
#Sets the URL string for where to store your vhd files - converts to https://azmonkeyplrs.blob.core.windows.net/vhds
#Also adds the VM name to the beginning of the file name
$DataDiskUri=$storageAcc.PrimaryEndpoints.Blob.ToString() + "vhds/" + $vmName
Add-AzureRmVMDataDisk -CreateOption empty -DiskSizeInGB 100 -Name $vmname-Data01 -VhdUri $DataDiskUri-Data01.vhd -VM $vmdiskadd -Caching ReadOnly -lun 0
#Updates the VM with the disk config - does not require a reboot
Update-AzureRmVM -ResourceGroupName $rgname -VM $vmdiskadd

On VM bring new disk online:

Get-Disk | Where-Object IsOffline –Eq $True | fl
Get-Disk | Where-Object IsOffline –Eq $True | Set-Disk –IsOffline $False

17

First command output shows disk number (2 in this case)

Initialize disk:

Initialize-Disk 2

Create new volume:

New-Partition –DiskNumber 2 -UseMaximumSize -AssignDriveLetter

18

And finally,format disk:

Format-Volume -DriveLetter E
Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s