possibly a LUN issue. Try adding a condition like below:
# Find the next available LUN
$lun = 0
while ($vm.DataDisks.Lun -contains $lun) {
$lun++ }
You can mark it 'Accept Answer' and 'Upvote' if this helped you
Regards,
Abiola
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello Everyone.
I am trying to add one OS disk as data disk into my vm using powershell. I am able to update the vm. after this it is not showing in portal.
are we need to add manually. I want to reduce this efforts as well. I really appreciate for quick reply.
8------------------------------------------------------------------------------------------
$rgName = "myResourceGroup"
$vmName = "RecoveryVM"
$location = "eastus"
$dataDiskName = "newOSDisk"
$disk = Get-AzDisk -ResourceGroupName $rgName -DiskName $dataDiskName
$vm = Get-AzVM -Name $vmName -ResourceGroupName $rgName
$vm = Add-AzVMDataDisk -CreateOption Attach -Lun 0 -VM $vm -ManagedDiskId $disk.Id
Update-AzVM -VM $vm -ResourceGroupName $rgName
possibly a LUN issue. Try adding a condition like below:
# Find the next available LUN
$lun = 0
while ($vm.DataDisks.Lun -contains $lun) {
$lun++ }
You can mark it 'Accept Answer' and 'Upvote' if this helped you
Regards,
Abiola