Tuesday, April 24, 2012

Change Pathing Policy Script

The following commands can be ran in PowerCLI to display / change the pathing policy of your datastores in ESX and ESXi.

!!! Before you perform any of these commands, I do recommend the ESX\ESXi host be placed in maintenance mode, to prevent any possible service interruptions!!!

'Display all Storage Information
Get-VMHost servername.your.domain | Get-ScsiLun | Select CanonicalName, MultiPathPolicy, Model

'Check Path Selection and path model name (model name will be needed later)
Get-VMHost servername.your.domain |Get-ScsiLun -LunType “disk” |format-table VMHost,CanonicalName,MultiPathPolicy,Model –autosize

The above command should give you results that look something like:


VMHost                            CanonicalName                   MultipathPolicy     Model
------                                 -------------                       ---------------         -----
servername.your.domain     naa.################a   Fixed                ABCD
servername.your.domain     naa.################b   Fixed                ABCD

' Using model name from above (ABCD), Verify selection criteria this criteria will be used on the next command to change things so verify to be sure you get the right results,
Get-VMHost servername.your.domain |Get-ScsiLun -LunType “disk” |where {$_.MultipathPolicy –ne “RoundRobin” -and $_.model -like “*ABCD*”} |format-table VMHost,CanonicalName,MultiPathPolicy,Model –autosize

' Change Path Selection for all luns that match the above selection criteria
Get-VMHost servername.your.domain |Get-ScsiLun -LunType “disk” |where {$_.MultipathPolicy –ne “RoundRobin” -and $_.model -like “*ABCD*”} |Set-ScsiLun -MultipathPolicy "RoundRobin"

' Run this command again, you should now get no results
Get-VMHost servername.your.domain |Get-ScsiLun -LunType “disk” |where {$_.MultipathPolicy –ne “RoundRobin” -and $_.model -like “*ABCD*”} |format-table VMHost,CanonicalName,MultiPathPolicy,Model –autosize

' Run this command and verify you get RoundRobin for all paths
Get-VMHost servername.your.domain |Get-ScsiLun -LunType “disk” |where {$_.model -like “*ABCD*”} |format-table VMHost,CanonicalName,MultiPathPolicy,Model –autosize

No comments:

Post a Comment