# LICENSE: GNU General Public License v2. (see LICENSE.txt)
# COPYRIGHT: Copyright 2010 Christian Heim <christian.heim@barfoo.org>
# Add the VI-Snapin if it isn't loaded already
if ( (Get-PSSnapin -Name "VMware.VimAutomation.Core" -ErrorAction SilentlyContinue) -eq $null )
{
Add-PSSnapin -Name "VMware.VimAutomation.Core"
}
if ($args.length -lt 2) {
Write-Host
Write-Host "fix_multipathing: "
Write-Host " - Display-Name of the vCenter cluster, we should check all LUNs"
Write-Host " on all available Hosts, and set the Path Selection Policy"
Write-Host " to the selected one."
Write-Host ""
Write-Host " - Path Selection Policy"
Write-Host " Possible:"
Write-Host " - RoundRobin (VMW_PSP_RR, Round Robin)"
Write-Host " - Fixed (VMW_PSP_FIXED, Fixed)"
Write-Host " - MostRecentlyUsed (VMW_PSP_MRU , Most Recently Used)"
Write-Host
exit 1
}
$vcserver = "vcenter.home.barfoo.org"
$cluster = $args[0]
$target_policy = $args[1]
# Since I do have only SVC-Disks connected to my hosts, I limit the search to those
$canonical_name = "naa.6005076801808021*"
Write-Host "Target vCenter Cluster: " $cluster
Write-Host "Target PSP: " $target_policy
Write-Host
switch ($target_policy) {
RoundRobin { $display_policy = "VMW_PSP_RR"; }
MostRecentlyUsed { $display_policy = "VMW_PSP_MRU"; }
Fixed { $display_policy = "VMW_PSP_FIXED"; }
default { Write-Warning "Unknown PSP selected! Please consult the help and try again."; exit }
}
Connect-VIServer $vcserver >/dev/null 2>&1
Write-Host "Found "@(Get-VMHost -location ( get-cluster $cluster ) | Get-ScsiLun -CanonicalName $canonical_name -LunType "disk" | where {$_.MultipathPolicy -ne $target_policy }).Count" LUNs in "$cluster" not using Path Selection Policy "$display_policy
Get-VMHost -location ( get-cluster $cluster ) | Get-ScsiLun -CanonicalName $canonical_name -LunType "disk" | where {$_.MultipathPolicy -ne $target_policy } | Set-ScsiLun -MultipathPolicy $target_policy >/dev/null 2>&1