VMware: List all RDM disks in Hosts and Virtual Machines via PowerCLI
To prepare a SAN to SAN migration I need to list all virtual machines with RAW Device Mappings, I found a very nice script at Pastebin (I’ve this you’re script, please comment to receive the credits), the script:
$report = @() $vms = Get-VM | Get-View foreach($vm in $vms){ foreach($dev in $vm.Config.Hardware.Device){ if(($dev.gettype()).Name -eq "VirtualDisk"){ if(($dev.Backing.CompatibilityMode -eq "physicalMode") -or ($dev.Backing.CompatibilityMode -eq "virtualMode")){ $row = "" | select VMName, VMHost, HDDeviceName, HDFileName, HDMode, HDsize, HDDisplayName $row.VMName = $vm.Name $esx = Get-View $vm.Runtime.Host $row.VMHost = ($esx).Name $row.HDDeviceName = $dev.Backing.DeviceName $row.HDFileName = $dev.Backing.FileName $row.HDMode = $dev.Backing.CompatibilityMode $row.HDSize = $dev.CapacityInKB $row.HDDisplayName = ($esx.Config.StorageDevice.ScsiLun | where {$_.Uuid -eq $dev.Backing.LunUuid}).DisplayName $report += $row } } } } $report
Ps. the script can take a while to list…
Wonderful, great script. I’m also busy with NetApp to NetApp migration
Cheers!!
Can you export this to .csv?
@dianilka
The only thing you have to do, to export it to CSV is to add | Export-CSV -NoTypInformation .csv
That’s all.
Do I need to simply copy the full script above and paste it into my Powercli? I did and nothing seems to happen?
Hi Matheen, the best thing you can do is copy the content of the script to notepad, then you save the file as “list_rdm.ps1”
Once you opened PowerCLI and connected vCenter server or host you can run the list_rdm.ps1 and you will get the result
hi all,
forgive me if i am asking worst, how can i run the above script from power cli, where i can learn about scripting from the scratch.
thanks in advance.
What is the command for exporting to a given location, like to a NAS or file share location?
Please disregard last post, I figured it out on my own
I run this and nothing works for me. I even try to do an echo $report and nada. It seems like it runs, but no output. Any Ideas?
Search for a file named report. Or change the first line and the last two lines in the script to “report.tom”. Then, after the script runs, search for “report.tom”.
OR
add this line to the end of the script:
Export-CSV -report.tom.csv
OR
copy the script into Kornshell, CShell, Bourne Shell or BASH or otherwise,as an executable unix script. Then invoke it from the command line by just typing in ‘report.tom’ . It will effectively be in an executable format I.E. (report.tom.exe). And May The Force Be With you!
Actually, skip that last suggestion, unless you are running on a Unix box.
If Exporting to CSV, how do you write the Output accross a csv sheet.
great script. verry usefull