The following PowerCLI script is an implementation of your pseudo code. I did not actually test the script. So it might not work the first time you run it.
$HostName="Server1"$Cont_Fix=1$Cont_MRU=1foreach ($LUNin (Get-VMHost-Name$HostName | Get-ScsiLun)) { # Get the number of paths for the LUN: $ScsiLunPath=$LUN | Get-ScsiLunPath $NumPaths=$ScsiLunPath | Measure-Object | Select-Object-PropertyCount # Balancing paths for a Fixed LUN: If ($Lun.MultipathPolicy -eq"Fixed") { # The technique is configure a preferred path for the Fixed LUNs and playing # with a module to determining which path can be preferred in each case. Set-ScsiLun-ScsiLun$LUN-PreferredPath$ScsiLunPath[($Cont_Fix%$NumPaths)+1] -Confirm:$false $Cont_Fix+=1 } # Balancing paths for a MRU LUN: If ($Lun.MultipathPolicy -eq"MostRecentlyUsed") { $Path_To_Set_Enabled= ($Cont_Mru%$NumPaths)+1 # The technique is: 1) Disabling all paths except one, which will have taken the active role: for ($Path_Count=1;$Path_Count++;$Path_Count-le$NumPaths) { if ($Path_Count-ne$Path_To_Set_Enabled) { Set-ScsiLunPath-Active$falseDisable_Path-ScsiLunPath$ScsiLunPath[$Path_Count] -Confirm:$false } } # 2) We again turn on the paths to normalize the status of the LUN: for ($Path_Count=1;$Path_Count++;$PathCount-le$NumPaths) { if ($Path_Count-ne$Path_To_Set_Enabled) { Set-ScsiLunPath-Active$trueDisable_Path-ScsiLunPath$ScsiLunPath[$Path_Count] -Confirm:$false } } $Cont_Mru+=1 } }if ($ScsiLun | Get-ScsiLunPath | Where-Object {$_.State -ne"Active"}) { "Oups. You need to review disabled paths" }else { "Yeah." }