0

vSphere 4.1 – Changing Path Selection Policy in Bulk

If you are like me, you will have come across the requirement to change the Path Selection Policy in vSphere.  For most people this is performed from the vSphere Client and requires you to select each lun for each datastore on each host and change the Path Selection Policy to either Fixed, Most Recently Used or Round Robin.
This is fine to do through the GUI for a single datastore across only a couple of hosts but recently I had to go through and do this for over 30 datastores across at least 10 hosts… performing this task through the GUI method would have taken me a good couple of hours to complete.

We had recently performed a firmware upgrade to our XIV Gen 2 unit which therefore allowed us to begin to take advantage of the VAAI features in vSphere (more information on this will follow).  On our previous XIV firmware version, we were advised to have our Path Selection Policy configured for Fixed but under the new version, the advice was to switch over to the preferred method of Round Robin.

I therefore performed a quick google and came across the article by the ‘VirtualServerGuy’ (http://www.virtualserverguy.com/blog/2010/9/22/modify-vsphere-path-selection-policy-in-bulk.html) which explained how to perform this task in a simpler way.

The details below are taken from that guide:
Start up the vSphere PowerCli – we have this installed on our vCenter server as we have scripts running to check for snapshots and path failures.

1.  Connect to your vCenter Server:
                     Connect-VIServer <vCenterServerName>

2.  List all of the hosts and disks that are on the XiV array that are not set for RoundRobin:

Get-VMHost | Get-ScsiLun -LunType “disk” | where {$_.MultipathPolicy –ne “RoundRobin” -and $_.model -like “*xiv*”}| format-table VMHost,CanonicalName,MultiPathPolicy –autosize
Here is some more information on this one-liner:
  • Get-VMHost – connects to each host under management by the vCenter server
  • Get-ScsiLun – gets SCSI LUNs of type “disk” (as opposed to a controller or something else) that have a MultiPath Policy that is not Round Robin and also have a model name that includes “XIV” in the name.
  • format-table – dumps a table listing the ESX host, the name of the LUN, and the current policy to the screen

The key thing now is to go through and change all of the Luns identified in one go, so instead of dumping a table to the screen, let’s pipe the results to the command Set-ScsiLun -MultipathPolicy “RoundRobin” .

The complete command is:

Get-VMHost | Get-ScsiLun -LunType “disk” | where {$_.MultipathPolicy –ne “RoundRobin” -and $_.model -like “*xiv*”}| Set-ScsiLun -MultipathPolicy “RoundRobin”

If you want to run the command first to verify that it will do what you expect it to do, then add the -whatif entry to the end of the line.  Once you are satisfied, remove the -whatif entry and the command will then make the changes.

I believe that this method went through and performed the change to all of my hosts and all of the relevant Luns in around 10 minutes automatically instead of me spending around two hours manually performing the same task.

Leave a Reply

Your email address will not be published. Required fields are marked *