Check correct path policy of RDMs

Our vSphere version combined with EMC VNX MCX OE version advices Round Robin as path policy. For RDMs used by a Microsoft Cluster however, Most-Recently-Used is the adviced policy. If a Microsoft Cluster has the incorrect path policy, there is a hughe latency on the RDM. We have noticed that reboot of the ESXi host or forced rescan of the HBA will reset the path policy selection.

To be able to keep an eye on unwanted changes in path policy, we use the famous vCheck by Alan Renouf and added our own plugin. 

$Report = @()
$GevondenMRULuns = 0
$Header = "" 

foreach($vm in (Get-View -ViewType VirtualMachine)){
 $vm.Config.Hardware.Device | where {$_.gettype().Name -eq "VirtualDisk"} | %{
 if("physicalMode","virtualmode" -contains $_.Backing.CompatibilityMode){
 $diskUUID = $_.Backing.LunUuid.Substring(10,32)
 $esx = Get-View $vm.Runtime.Host
 $lun = $esx.Config.StorageDevice.ScsiLun | where {$_.CanonicalName.Split(".")[1] -eq $diskUUID}
 if($lun){
 $lunscsi = Get-VMHost $esx.Name | Get-ScsiLun -CanonicalName $lun.CanonicalName 

 If( $lunscsi.MultipathPolicy -ne "MostRecentlyUsed" )
 {
 # NOT mru
 $row = "" | Select ESXiHost, CanonicalName, MultiPathPolicy, VMName, Status
 $row.ESXiHost = $esx.name
 $row.CanonicalName = $lun.canonicalname
 $row.MultiPathPolicy = $lunscsi.Multipathpolicy
 $row.VMName = $vm.Name
 $row.Status = "ERROR"
 $Report += $row

 }
 else
 {
 # MRU
 $GevondenMRULuns = $GevondenMRULuns + 1

 $row = "" | Select ESXiHost, CanonicalName, MultiPathPolicy, VMName, Status
 $row.ESXiHost = $esx.name
 $row.CanonicalName = $lun.canonicalname
 $row.MultiPathPolicy = $lunscsi.Multipathpolicy
 $row.VMName = $vm.Name
 $row.Status = "CORRECT"
 $Report += $row

 }
 }
 }
 }
}

$Header = "RDMs with incorrect pathpolicy $(@($Consol).Count-1), RDMs with CORRECT pathpolicy $GevondenMRULuns"
$Title = "RDMs with incorrect path"
$Comments = "Path policy can either by Fixed Path, Most Recently Used or Round Robin. For physical RDMs the MRU policy is adviced"
$Display = "Table"
$Author = "Gabrie van Zanten"
$PluginVersion = "1"
$PluginCategory = "vSphere"

# Output to console
$Report

$Header

</pre>
<pre>