Friday, April 29, 2011

Change path selection policy using PowerShell

So I've discovered that I can do bulk changes to the path selection policy settings within vSphere using PowerShell and the VI Toolkit. The is very useful because I cannot set a default path selection policy with vSphere 4.1. So presentation of several new LUN's can be quite a pain without this script.

Get-VMHost | where {$_.State -eq “Maintenance”} | '
Get-ScsiLun -LunType "disk" | where {$_.MultipathPolicy –ne "RoundRobin"} | `
Set-ScsiLun -MultipathPolicy "RoundRobin"

The above script will; Select all hosts in maintenance mode, select each LUN that is not using RoundRobin and then configure each LUN to use RoundRobin for the path selection policy.

The ' in the syntax is used to move to the next line in the console so you don't have to scroll to the right or word wrap. Leave in or take out, either should allow it to work.

We can modify the above script so that it will work with a specified host instead of any host in maintenance mode;

Get-VMHost "hostname" | '
Get-ScsiLun -LunType "disk" | where {$_.MultipathPolicy –ne "RoundRobin"} | '
Set-ScsiLun -MultipathPolicy "RoundRobin"

It is important to note that both of the above commands will modify the path selection policies for each LUN presented to the host, including those that have not yet been set up as a datastore with a VMFS partition.

No comments:

Post a Comment