VMware iSCSI Multipath (set all PSPs)

iSCSI Multipath Post 1 (basic)
iSCSI Multipath Post 2 (Equallogic script)
iSCSI Multipath Post 3 (vSphere5)

I found a script at VMware’s PowerShell blog about setting all your LUN Path Selection Policy’s to Round Robin. This is a great trick when you are setting up iSCSI multipathing and you don’t want to take an hour setting all your iSCSI LUNs to Round Robin in the GUI.

Run this command to connect to your vCenter server:
Connect vi-server [vcenter server name]

Since I only had a handful of hosts I ran this command for each host before kicking off the script. In a larger environment you might script this out, but I like knowing what host it is running against and when
$hostview = get-view -viobject [FQDN of host]

I added the first line to the script posted at the VMware blog (they had the line listed in the setup but not the script itself)

#StartScript
$storagesystem = get-view $hostview.configmanager.storagesystem
# This script block sets any LUN with more than one path to the round-robin policy.
# Handle with care, this could easily cause you major problems!
$policy = new-object VMware.Vim.HostMultipathInfoLogicalUnitPolicy
$policy.policy = “rr”
$storageSystem.StorageDeviceInfo.MultipathInfo.lun |
where { $_.Path.length -gt 1 } |
foreach { $storageSystem.SetMultipathLunPolicy($_.ID, $policy) }
#EndScript

paste that block of text into a file with a .ps1 extention and save it in your scripts director: C:Program Files (x86)VMwareInfrastructurevSphere PowerCLIScripts>
kick the script off (after the two lines above) by using “.scriptname.ps1” w/o the quotes.

For each additional host run “$hostview = get-view -viobject [FQDN of host]” followed but the script.

Do not run this if your storage vendor doesn’t recommend Round Robin or in a mixed SAN environment.

Note that this is tried and testing using PowerCLI5 against 4.1 hosts. YMMV.

Update: A couple niftly one-liners to check each host or cluster for PSP can be found at vmpros.nl

This entry was posted in PowerShell, Scripting, Storage, Virtualization, VMware and tagged , , , , , . Bookmark the permalink.

Leave a Reply