VMware Cloud Community
sureshadmin2011
Enthusiast
Enthusiast
Jump to solution

Extract RDM details

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!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

sureshadmin2011
Enthusiast
Enthusiast
Jump to solution

Thanks Luc. Works perfect !

You are a champ Smiley Happy

0 Kudos
wamatha
Contributor
Contributor
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos