PowerCLI script for changing pathing policy en masse

Say you deploy a new SAN, and you’re in the process of migrating all your VM’s from the old datastores to the new. When you go to add the new datastores, ESX sets the incorrect pathing policy so now you have to go change it on each and every datastore, on each and every ESX server. I’ve had to go through this and it’s a pain in the bum.

Here’s a small PowerCLI script I wrote that will save you the hassle of doing it by hand.

Connect-VIServer SERVER
$esxservers = Get-Datacenter "DATACENTRE" | Get-VMHost
foreach ($server in $esxservers) {
Get-VMHost "$server" | Get-ScsiLun -CanonicalName "naa.6005076802808*" | Set-ScsiLun -MultipathPolicy "RoundRobin"
}

This script will connect to the vCenter Server, pull a list of all the ESX servers in the Datacenter, collect a list of all the disks matching the specified CanonicalName, then set the policy to RoundRobin.

Hope you find it useful.

Leave a Comment

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

Scroll to Top