Hi,
I need a script to extract below given fields of all the RDM disks presented to a VM to a CSV file. It's ESX 3.5 infra.
Virtual device node
Physical LUN
Datastore mapping file
Thanks!
Does this produce what you want ?
Get-VM | Get-HardDisk -DiskType "rawVirtual","rawPhysical" | Select @{N="VM";E={$_.Parent.Name}}, @{N="DevId";E={ $cKey = $_.Extensiondata.ControllerKey $controller = $_.Parent.Extensiondata.Config.Hardware.Device | where {$_.Key -eq $cKey} "{0} ({1}:{2}) {3}" -f $controller.DeviceInfo.Label.Split(' ')[0], $controller.Busnumber, $_.Extensiondata.UnitNumber, $_.Name }}, @{N="LUN";E={$_.DeviceName}}, @{N="DS Mapping";E={$_.Extensiondata.Backing.FileName}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Does this produce what you want ?
Get-VM | Get-HardDisk -DiskType "rawVirtual","rawPhysical" | Select @{N="VM";E={$_.Parent.Name}}, @{N="DevId";E={ $cKey = $_.Extensiondata.ControllerKey $controller = $_.Parent.Extensiondata.Config.Hardware.Device | where {$_.Key -eq $cKey} "{0} ({1}:{2}) {3}" -f $controller.DeviceInfo.Label.Split(' ')[0], $controller.Busnumber, $_.Extensiondata.UnitNumber, $_.Name }}, @{N="LUN";E={$_.DeviceName}}, @{N="DS Mapping";E={$_.Extensiondata.Backing.FileName}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Or if you prefer to see the CanonicalName for the LUN property.
Get-VM | Get-HardDisk -DiskType "rawVirtual","rawPhysical" | Select @{N="VM";E={$_.Parent.Name}}, @{N="DevId";E={ $cKey = $_.Extensiondata.ControllerKey $controller = $_.Parent.Extensiondata.Config.Hardware.Device | where {$_.Key -eq $cKey} "{0} ({1}:{2}) {3}" -f $controller.DeviceInfo.Label.Split(' ')[0], $controller.Busnumber, $_.Extensiondata.UnitNumber, $_.Name }}, @{N="LUN";E={ if($_.DeviceName){ $devName =$_.DeviceName ($_.Parent.Host.Extensiondata.Config.StorageDevice.ScsiLun | where {$_.Key.Split('-')[-1] -eq $devName.Split('.')[1]}).CanonicalName } }}, @{N="DS Mapping";E={$_.Extensiondata.Backing.FileName}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc. Works perfect !
You are a champ
This works great Lucd,
How can I export the results to cvs file?
Is it also possible to add the size of the RDM in the script?
Thank you
Joseph
To export to a CSV, just pipe the result to Export-Csv.
Add to the end the following
... | Export-Csv "C:\report.csv" -NoTypeInformation -UseCulture
(without the dots of course).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference