Quickly Change Path Selection Policy for ESXI Hosts using PowerCLI

Quickly Change Path Selection Policy for ESXI Hosts using PowerCLI

This is a quick post about how to change the path selection policies of multiple ESXI hosts within VCenter. It’s typically a best practice for most storage array vendors to want VMware host path selection policy ( PSP ) to align with the best practices of the storage array. This post shows you how to change all existing LUNs to the desired PSP and change the default PSP for all new LUNs that are created. The path selection policy options are the following below and can be found on the VMware website at the link below.

Setting a Path Selection Policy

Fixed (VMW_PSP_FIXED) -The host uses the designated preferred path, if it has been configured. Otherwise, it selects the first working path discovered at system boot time. If you want the host to use a particular preferred path, specify it manually. Fixed is the default policy for most active-active storage devices.

Most Recently Used(VMW_PSP_MRU) –¬†The host selects the path that it used most recently. When the path becomes unavailable, the host selects an alternative path. The host does not revert back to the original path when that path becomes available again. There is no preferred path setting with the MRU policy. MRU is the default policy for most active-passive storage devices.

Round Robin(VMW_PSP_RR) – The host uses an automatic path selection algorithm rotating through all active paths when connecting to active-passive arrays, or through all available paths when connecting to active-active arrays. RR is the default for a number of arrays and can be used with both active-active and active-passive arrays to implement load balancing across paths for different LUNs.

First, I will show the manual process of changing the path selection policy from the VMware web client. In this example, we will change the path selection policy on an ISCSI LUN from Most Recently Used to Round Robin from the VMware web client.

Manually Changing Path Selection Policy

1. Click on the Datastores tab from the vSphere Web Client and then click “Connectivity and Multipathing”. Select one of your hosts. Notice the path selection policy is “Most Recently Used.” Also make note of the Storage Array Type Policy, “VMW_SATP_ALUA”. We will use this information later when we configure the default PSP for newly created LUNs to always be Round Robin.

2. Click the “Edit Multipathing” tab. Then use the drop down menu to select your PSP. In this case, we are selecting “Round Robin.” Click “OK” And now we notice that the PSP now shows “Round Robin”

Wow, that was easy you say. Just a couple of clicks!!! Oh but wait. This has to be done on every host, for every LUN. So if you have 20 ESXI hosts with 30 LUNs, multiplied by about 3 clicks per settings change, we’re looking at about 1800 mouse clicks!!! Ok, so there has to be a better more efficient way to perform this task. Here’s how….

Change Path Selection Policy with Power CLI

1. Launch PowerCLI and connect to the VCenter Server that manages your hosts.

connect-viserver -server MyVCenter -protocol https -user administrator@MyDomain -password MyPassword


2. Run the following command to list all LUNs that have a PSP of “MostRecentlyUsed.” Notice we have four LUNs all using the “MostRecentlyUsed” Path Selection Policy.

get-vmhost | get-scsilun | where-object {$_.multipathpolicy -eq "Mostrecentlyused" }

3. Run the following command to change the PSP for all LUNs using “MostRecentlyUsed” to “Round Robin” on all hosts.

get-vmhost | get-scsilun | where-object {$_.multipathpolicy -eq "Mostrecentlyused" } | set-scsiLUN "RoundRobin"

And that’s it. Every host within your VCenter environment is now using the RoundRobin multipathing policy. Be sure to consult with your storage vendor documentation about the best PSP for your particular storage array.

Set Default PSP for New LUN Creation

So the previous examples change all existing LUNs to the desired PSP. However, new LUNs will continue to get created by default with the old PSP policy unless we change the default setting. We will make this change in PowerCLI as well.

1. While connected to the VCenter PowerCLI session, run the following commands to change the default PSP Policy. ( Just Copy and Paste All of the Command into the PowerCLI Window. ) Note: Change the “$NEWPSP” variable ( Line 3) to a different PSP if desired. Also above we noted the $LoadedSATP variable ( Line 7). If this is different for your array, this variable will need to be changed as well.

# Changing PSP Policy to Round Robin


# Setting Curently Loaded SATP


# Getting All Hosts in VCenter and Changing PSP Policy


$S = 0

foreach ($ESXI in $ALLESXIHOSTS)
$esxcli = get-esxcli -vmhost $ESXI

Write-Progress -Activity "Changing Default PSP of All Hosts" -status "Configured: $S of $($ALLESXIHOSTS.Count)" -PercentComplete (($S / $ALLESXIHOSTS.Count) * 100)


Now going forward every time we create a new Datastore, the desired PSP will be set. As always, I hope you all found this post helpful and thanks for reading.

Author: johnter23