PowerCLI Script to change the Multipathing Setting

 

I had a requirement to change the VMware Path Selection Policy (PSP) to Round Robin for more than 200 ESXi servers connected with more than 150 datastores. Manually get this done was a time consuming and thought to write an automated powercli script to enter host into maintenance mode and change PSP to Round Robin then release host back to production.

Provide the vcenter hostname or IP and enter the list of servers in the “esxnames.txt” file and execute the script. PSP Updated datastores will exported in to a csv file for later reference in case required. 

Hope this will save lot time for some one has a similar requirement. 

 

Connect-VIServer vCENTER hostname or IP

Get-Content -Path .\esxnames.txt -PipelineVariable esxName |

ForEach-Object -Process {

$esx = Get-VMHost -Name $esxName

# Enter Host into Maintenance Mode

write-host “Entering Host $esx into Maintenance Mode”

Set-VMHost -VMHost $esx -State Maintenance -Confirm:$false -RunAsync | Out-Null

while($esx.State -ne ‘Maintenance’){

sleep 5

$esx = Get-VMHost -Name $esx.Name

}

#Multipathing change
write-host ” “
write-host “Changing path selection policy to Round Robin for the storage devices connected to $esx”

Get-VMhost $esx | Get-ScsiLun -LunType disk | Where { $_.MultipathPolicy -notlike “RoundRobin” } | Set-ScsiLun -MultipathPolicy “RoundRobin”

# Exit Host From Maintenance Mode
write-host ” “
write-host “The storage device list have been inserted to csv file.”
write-host ” “
write-host “Exit Host $esx From Maintenance Mode”

Set-VMHost -VMHost $esx -State Connected -Confirm:$false -RunAsync | Out-Null

while($esx.State -ne ‘Connected’){

sleep 5

$esx = Get-VMHost -Name $esx.Name
write-host ” “
write-host “————————————–“
write-host “Continuing to Next Host”
}

} | export-csv -useculture -notypeinformation -path .\multipathreport.csv
write-host “No more hosts.”
write-host “Change completed for the provided hosts.”

write-host “Report Exported.”

Rating: 0.5/5. From 1 vote.
Please wait...

You may also like...

Leave a Reply

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

PowerCLI Script to change the Multipathing Setting

time to read: <1 min
0