These last few weeks, I’ve been toying with PowerCLI (and PowerShell for that matter). One thing I do have to say, is that Microsoft finally did it right! It’s a useable, program-able command line interface for Windows after all! Thanks to Ivo Beerens and his post “Best practices for HP EVA, vSphere 4 and Round Robin multi-pathing“, I was able to come up with the below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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 |
This works great, however you could make it work on the whole vCenter inventory, which I don’t want. We usually add LUNs to a single cluster at one time. Only thing you might need to change, is the canonical name. Mine simply says “find all SVC LUNs” and you might need to change it, if you’re using a different storage.