Changing the path policy of the SCSI lun device using Powercli in Vmware Vsphere Environment



Today my motto is to change the path policy of the scsi lun from Fixed to round robin. It’s always a pain to change the path policy of the scsi lun device, it takes hours of time to change the path manually in case if we have the large environments of say 2000 ESXi and with more than 400 Devices connected with the Esxi.

so we used some Powercli and create a loop to perform the redundant task well in crisp words we tried to automate this task which could save hours of manual works

Code:

$server = Get-content "C:\hostfile.txt"foreach ($i in $server){
Get-ScsiLun -VmHost $i -CanonicalName "naa.6006*" | where {$_.MultipathPolicy -ne "RoundRobin"} | Set-ScsiLun -MultipathPolicy RoundRobin}

Here in the above code I am calling the list of ESXi Host in the file named as hostfile.txt and passing it to the variable $server and this will create an array of characters over the variable $server , Each character represents Esxi hosts on devops terms, then each host is passed on to the $i variable and loop is created using foreach. This is the logical flow of the script.

Now Moving ahead core functions of the script are the below one :

Get-ScsiLun -VmHost $i -CanonicalName "naa.6006*" –disktype disk | where {$_.MultipathPolicy -ne "RoundRobin"} | Set-ScsiLun -MultipathPolicy RoundRobin

Here Get-ScsiLun -VmHost $i -CanonicalName "naa.6006*" –disktype disk connects to the host and checking with the lun disks that has “naa.6006” with the disk type of disk.

And  where {$_.MultipathPolicy -ne "RoundRobin"} represents and sorts the disk that are not RoundRobin and this function is like filtering out the outputs

Finally the above one will identify the SCSI luns and Disks which not set with Roundrobin, now its time to be reactive by making the changes to Lundisk paths to RoundRobin using Set-ScsiLun -MultipathPolicy RoundRobin , Voila Amigo we have changed the Storage Path policy from Fixed to Roundrobin.

Tweet with me @sayhi2vignesh

Popular posts from this blog

How to reset the IE settings Through command Line (CMD)

Running CLI Commands in ESXi using plink software