your home for end-user virtualization!

List Hostname, Lun Name, Lun Policy, and Path State using PowerCLI

So the other day, EMC wanted to verify that all luns on my ESX host were using the same Lun Policy as a result of an open ticket that I had with them. To do that, I decided to use the PowerCLI toolkit. This is what I came up with.


$lunpathinfo = @()
foreach ($vmhost in get-cluster "CLUSTER" | get-vmhost) {
$hostview= get-view $vmhost.id
$hostview.config.storagedevice.multipathinfo.lun | % { `
    $lunname=$_.id
    $lunpolicy=$_.policy.policy
    $_.path | % {
        $pathstate=$_.pathstate
        $lunpathinfo += "" | select @{name="Hostname"; expression={$vmhost.name}},
                                    @{name="LunName"; expression={$lunname}}, 
                                    @{name="LunPolicy"; expression={$lunpolicy}}, 
                                    @{name="PathState"; expression={$pathstate}}
    }
}
}
$lunpathinfo | export-csv c:\host_luns.csv 

Search

Categories