Disk is not visible in portal

Mohsin Khan 45 Reputation points
2024-07-20T13:15:23.9733333+00:00

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

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,551 questions
Azure Disk Storage
Azure Disk Storage
A high-performance, durable block storage designed to be used with Azure Virtual Machines and Azure VMware Solution.
600 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,309 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. akinbade abiola 8,625 Reputation points
    2024-07-20T20:26:43.7766667+00:00

    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

    0 comments No comments