Is there a way in Azure to find if a VM in azure created to with Managed/Unmanaged disks?
We can use PowerShell to list the information of Azure VM.
Here is the Unmanaged disks VM output:
PS C:\Users> (get-azurermvm -ResourceGroupName jasonvn -Name jasonvm1).StorageProfile.OsDisk
StorageProfile and NetworkProfile, respectively.
OsType : Linux
EncryptionSettings :
Name : jasonvm1
Vhd : Microsoft.Azure.Management.Compute.Models.VirtualHardDisk
Image :
Caching : ReadWrite
CreateOption : FromImage
DiskSizeGB :
ManagedDisk :
Here is the Managed disks VM output:
PS C:\Users> (get-azurermvm -ResourceGroupName jasonvn -Name jasonvm).StorageProfile.OsDisk
StorageProfile and NetworkProfile, respectively.
OsType : Linux
EncryptionSettings :
Name : jasonvm
Vhd :
Image :
Caching : ReadWrite
CreateOption : FromImage
DiskSizeGB : 30
ManagedDisk : Microsoft.Azure.Management.Compute.Models.ManagedDiskParameters
Another way, we can use Azure new portal to check automation script to find it:
This information is available in another area of the Azure portal as well. Go to the 'Virtual machines' list in the portal, click the 'Columns' button, and add a column called "Uses Managed Disks".
We can use PowerShell to list the information of Azure VM.
Here is the Unmanaged disks VM output:
PS C:\Users> (get-azurermvm -ResourceGroupName jasonvn -Name jasonvm1).StorageProfile.OsDisk
StorageProfile and NetworkProfile, respectively.
OsType : Linux
EncryptionSettings :
Name : jasonvm1
Vhd : Microsoft.Azure.Management.Compute.Models.VirtualHardDisk
Image :
Caching : ReadWrite
CreateOption : FromImage
DiskSizeGB :
ManagedDisk :
Here is the Managed disks VM output:
PS C:\Users> (get-azurermvm -ResourceGroupName jasonvn -Name jasonvm).StorageProfile.OsDisk
StorageProfile and NetworkProfile, respectively.
OsType : Linux
EncryptionSettings :
Name : jasonvm
Vhd :
Image :
Caching : ReadWrite
CreateOption : FromImage
DiskSizeGB : 30
ManagedDisk : Microsoft.Azure.Management.Compute.Models.ManagedDiskParameters
Another way, we can use Azure new portal to check automation script to find it:
Similar to Scottge's answer, but if you just go to the VM > Disks > select the disk, it opens a blade showing the disk information. At the top of this blade, "(unmanaged)" is displayed after the disk name if it is unmanaged. Nothing is displayed if it is managed.
To add to Jason Ye's answer, you can also run a similar command in Azure CLI 2.0. The command is:
az vm show -g rg_name -n vm_name
And the output for non-managed disk is:
...
"osDisk": {
"caching": "ReadWrite",
"createOption": "fromImage",
"diskSizeGb": 32,
"encryptionSettings": null,
"image": null,
"managedDisk": null,
"name": "rhel-un",
"osType": "Linux",
"vhd": {
"uri": "https://storageaccountname.blob.core.windows.net/vhds/....vhd"
}
And for managed disk:
...
"osDisk": {
"caching": "ReadWrite",
"createOption": "fromImage",
"diskSizeGb": 32,
"encryptionSettings": null,
"image": null,
"managedDisk": {
"id": "/subscriptions/sub_id/resourceGroups/rg_name/providers/Microsoft.Compute/disks/rhel_OsDisk_1...",
"resourceGroup": "rg_name",
"storageAccountType": "Standard_LRS"
},
"name": "rhel_OsDisk_1...",
"osType": "Linux",
"vhd": null
}
If looking for OS disk, this will work. Can mod for data disk.
$VmName="vmNameHere" #vmNameHere
$RGName="rgnameHere" #resourceGroupname
if((Get-AzureRmVM -Name $VmName -ResourceGroupName $RGName).StorageProfile.OsDisk.ManagedDisk -like ''){"$vmName,OS Disk,Unmanaged"}else{"$Vmname,OS Disk,Managed"}
Here is one way which I found, follow the below steps to determine the disk type:
- Login to the Azure portal.
- Select the VM in question. Select the
- disk to check. Look at the disk's URL.
An Unmanaged Disk's URL will look like:
/storage_account_name.blob.core.windows.net/VM_name/VM_name.vhd
A Managed Disk's URL will look like:
/subscriptions/0cbded86-6088-430c-a320-xxxxxxxxxxxx/resourceGroups/Resource_Group_name/providers/Microsoft.Compute/disks/Disk_name
This thread is a few years old, but I've found a better way to check them all at once using Powershell. Microsoft just emailed out that they're retiring unmanaged disks in 2 years, so hopefully this helps others before then!
This will try to connect to Azure, install the module if needed, get all your VMs, and list out the disk name and ManagedDisk field. If you have a lot of VMs I'd suggest adding a filter to only show when the ManagedDisk field is empty.
Try{Get-AzSubscription > Out-Null}
Catch{
Try{Get-Module -ListAvailable -Name AZ.compute}
Catch{
Write-Host "Azure module does not exist, installing, importing, and connecting" -ForegroundColor Cyan
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-Module Az -Repository PSGallery -Force
}
Finally{
Import-Module AZ
Write-Verbose "Enter your Azure Admin Account creds" -ForegroundColor Cyan
Connect-AzAccount
Set-AzContext -Subscription "fe95db19-b91b-4492-990e-8c7c9ac355a4"
}
}
Finally{
Write-Host "You are connected to Azure" -ForegroundColor Cyan
}
#Get All VMs
$VMs = Get-AZVM
#Go through each VM one at a time
ForEach($VM in $VMs){
$VM.StorageProfile.OsDisk | Select Name,ManagedDisk
$VM.StorageProfile.DataDisks | Select Name,ManagedDisk
}
It is shown in Virtual Machine JSON preview as well under osDisk
© 2022 - 2024 — McMap. All rights reserved.