I'm actually training for AZ-104, and while working on adding data disk to virtual machine with command line, I had this error :
Saying that the disk "newdisk02" was not found. But I checked and the disk exist, but in a different location than the vm.
VM location : West Europe
Disk location : North Europe
I changed the disk location to the same as the VM in the script and the disk was added successfully.
I don't understand why it is not possible for a disk to be in a different location than the vm. Maybe it is a silly question lol I don't know.
Can someone explain please ?
Here is the script :
$resourcegroup = 'test-grp'
$machinename = 'demolinux'
$location = 'North Europe'
$storageType = 'Standard_LRS'
$dataDiskName = 'newdisk02'
$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