So at first allow us to create and initialize some variables that we are going to use for creating information disk.
So first is the useful resource group and my useful resource group identify is anish-grp so this variable holds the anish-grp.
- $resourcegroup = ‘anish-grp’
This variable holds the placement of the machine. So at the moment demovm is within the East US location so I’ve given my location as East US.
- $location = ‘East US’
The following one is the disk kind and I am including a regular disk. So this variable holds the disk kind. I’m utilizing a regular disk due to pricing components.
- $storageType = ‘Standard_LRS’
The following one is the diskname that we wish to be created. This variable holds the diskname that’s demodatadisk and the subsequent one holds the dimensions of the disk.
- $dataDiskName = ‘demodatadisk’
So after initializing the disks, now we have to execute some extra instructions to create the info disk. So let’s execute the subsequent command.
So now we have to create a brand new disk configuration and beneath is the command to do this and we’re utilizing the variables now we have initialized.
- $datadiskConfig = New-AzDiskConfig -SkuName $storageType -Location $location -CreateOption Empty -DiskSizeGB $dataDiskSize
After creating the configuration now are we’re going to create a brand new disk.
- $dataDisk01 = New-AzDisk -DiskName $dataDiskName -Disk
Now we have to get a reference of a digital machine on which we’re going to connect the disk. So we’ll get a reference to the digital machine and that’s demovm.
- $datadiskConfig -ResourceGroupName $resourcegroup
Now we’re going to add an information disk to the digital machine and beneath is the command for that. I’ve assing LUN to 1 as a result of after I created the info disk and connected the disk on this article, the LUN was zero for this disk it will be 1.
- $vm = Add-AzVMDataDisk -VM $vm -Title $dataDiskName -CreateOption Connect -ManagedDiskId $dataDisk01.Id -Lun 1
After this command, we have to replace the digital machine, and beneath is the command to do this. So allow us to replace the digital machine.
- Replace-AzVM -VM $vm -ResourceGroupName $resourcegroup
Now, should you go to all sources and verify for the disk, you will need to discover the newly created disk there.
On this article, we noticed tips on how to create and fasten information disks to Azure digital machine utilizing PowerShell and the way simple it’s.
Thanks for studying.