Articles → MICROSOFT AZURE → Create The Data Disk In Azure Using PowerShell

Create The Data Disk In Azure Using PowerShell






PowerShell Command




$resourcegroup = 'RG'
$machinename = 'myVM'
$location = 'North Europe'
$storageType = 'Standard_LRS'
$dataDiskName = 'newdisk01'
$dataDiskSize = 20
 
$datadiskConfig = New-AzDiskConfig -SkuName $storageType -Location $location -CreateOption Empty -DiskSizeGB $dataDiskSize
 
$dataDisk01 = New-AzDisk -DiskName $dataDiskName -Disk $datadiskConfig -ResourceGroupName $resourcegroup
 
$vm = Get-AzVM -Name $machinename -ResourceGroupName $resourcegroup
 
$vm = Add-AzVMDataDisk -VM $vm -Name $dataDiskName -CreateOption Attach -ManagedDiskId $dataDisk01.Id -Lun 1
 
Update-AzVM -VM $vm -ResourceGroupName $resourcegroup


Picture showing the powershell script for creating a data disk in Azure
Click to Enlarge


Output


Picture showing the data disk created in Azure portal
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Monday, April 19, 2021

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250