In today's we will look at how to list VMs with RDM using PowerCLI. The idea behind the article came to my mind when I was working with one of the users.
The customer wanted to perform a SAN to SAN migration and there were a lot of Virtual Machines with RDMs configured.
I first performed a Google search and could find a few scripts available but most of them were lengthy and cumbersome.
I was looking at probably a one-liner which would list the Virtual Machine name along with the RDM details.
The one-liner that I wrote will list the below details:
- Virtual Machine Name.
- Hard Disk Name.
- Disk Type (Physical or Virtual compatibility).
- LUN ID of the device.
- VML ID of the device.
- VMDK File name.
- The size of the RDM LUN.
Before you run this command, kindly connect to the vCenter Server or the ESXi host using the Connect-VIServer cmdlet.
Get-VM | Get-HardDisk | Where-Object {$_.DiskType -like "Raw*"} | Select @{N="VMName";E={$_.Parent}},Name,DiskType,@{N="LUN_ID";E={$_.ScsiCanonicalName}},@{N="VML_ID";E={$_.DeviceName}},Filename,CapacityGB | Export-Csv C:\Users\Adil\Desktop\RDM-list.csv -NoTypeInformation
The output of the CSV file will look something like below.
I hope this has informative and thank you for reading!
11 Comments
Thanks a lot for this! I’ve been trying to also add on which host the virtual machine resides but to no avail ( I have a cluster setup). would it be possible to help out please?
You can use this $_.Parent.VMHost.Name to get on which ESXi host the VM is registered. Cheers!
Hello Adil,
Thanks for great script.
Mean while could you please help where I can add “$_.Parent.VMHost.Name” Is it possible you to give the script with adding this .
Hello Govind,
The updated script would be as below.
Get-VM | Get-HardDisk | Where-Object {$_.DiskType -like “Raw*”} | Select @{N=”VMName”;E={$_.Parent}},@{N=”ESXi Host”;E={$_.Parent.VMHost.Name}},Name,DiskType,@{N=”LUN_ID”;E={$_.ScsiCanonicalName}},@{N=”VML_ID”;E={$_.DeviceName}},Filename,CapacityGB | Export-Csv C:\Users\Adil\Desktop\RDM-list.csv -NoTypeInformation
Hi Adil,
thanks for that great post.
I try to display additional the LUN-Number (not the LUN-ID). But i can´t find the correct parameter.
Is this possible?
Thanks.
I wish to learn the VMware PowerCLI. Do we have any link or article where I can refer and start learning from basics. Please help me.
Check VMware documentation, that should be a good start.
Hi Sir,
I am new to VMware. I need to setup the vSphere lab. i saw your post below,
http://adil-arif.com/how-to-setup-vmware-vsphere-lab-in-vmware-workstation/
I need the know, how to follow other pages. Please help me
What an AWESOME script!!!! Exactly what was needed. Great Work!
Thanks!
This very useful.
fantastic work and still works amazingly