VMware Cloud Community
dawoo
Enthusiast
Enthusiast
Jump to solution

Manually load balancing / setting LUN paths.

I'm wanting to manually load balance my LUNs, there are 4 paths and I'd like to cycle each LUN through the next path and loop back round. Am using vSphere 4 Update 1.

Looking through the web I've found these two articles provide the code I'm after but both error for me.

http://vmjunkie.wordpress.com/2009/01/29/balancing-lun-paths-on-your-esx-hosts-with-powershell/

http://doitsmarter.blogspot.com/

-


  1. Get information from user

$vc = Read-Host "Please enter the vCenter Server name:"

$uname = Read-Host "Please enter the username to connect to the vCenter server:"

$upass = Read-Host "Please enter the associated password:"

$clusterName = Read-Host "Please enter the Cluster name:"

Write-Host "Connecting to vCenter server $vc, please wait." -BackgroundColor Black -ForegroundColor White

Connect-VIserver $vc -user $uname -password $upass | Out-Null

###

  1. Retrieve ESX hosts in Cluster

$VMHosts = Get-Cluster $clusterName | Get-VMHost

  1. Run through this loop for each host in the cluster

foreach ($VMHost in $VMHosts)

{

$luns = @($VMHost|get-scsilun -luntype disk| where-object {$_.ConsoleDeviceName -like "/vmfs/devices/disks/vml*"} | Sort-Object CanonicalName)

$firstLUNPaths = Get-ScsiLunPath $luns[0]

$numPaths = $firstLUNPaths.Length

$count = 0

foreach ($lun in $luns)

{

if ($count -ge $numPaths)

{

$count = 0

}

$paths = Get-ScsiLunPath -ScsiLun $lun

$lun|Set-ScsiLun -MultipathPolicy Fixed -PreferredPath $paths[$count]

$count += 1

  1. Sleep for 30 seconds to prevent array saturation.

Start-Sleep -Seconds 30

}

}

-


Initially I found the script stumbled on the $luns[0] implying the value is null or empty. I Replaced vml with naa. Now I receive "One or more missing mandetory parameters SCSI LUN". I assumed an error with the syntax but am not able to establish quite what.

Now, if I run some of the commands at the command line I find I get out usable output. But by piping the same line into an array or variable then Write-Host of the content I see "VMware.VIMAutomation.ViCore.Impl.V1" (and so on).

Judging by the dates of the blog posts I'm of the opinion the latest PowerCLI (v4 build 264274) may be returning the information in a different manner, I am correct with my assumption?

Can you guess what my next question will be? How would I do this now?

Any assistance is appreciated and rewarded (in points not beer).

Thanks,

Darren.

10 Print "It's all about the Nerdknobs" , 20 GOTO http://blog.vmote.net/
Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The "vml", "naa"... depends on the type of storage your LUNs are located on.

The problem with the next statement is that you need to specify the -Scsilun parameter.

This can be a positional parameter (without -Scsilun) but then it has to come in position 2.

See the Get-ScsiLunPath page.

Try the attached script.

I changed that line and it works for me.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

The "vml", "naa"... depends on the type of storage your LUNs are located on.

The problem with the next statement is that you need to specify the -Scsilun parameter.

This can be a positional parameter (without -Scsilun) but then it has to come in position 2.

See the Get-ScsiLunPath page.

Try the attached script.

I changed that line and it works for me.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
dawoo
Enthusiast
Enthusiast
Jump to solution

Many thanks (again) LucD.

Amended script works like a a treat, not that I doubted it by the way.

Cheers,

Darren.

(@dawoo)

10 Print "It's all about the Nerdknobs" , 20 GOTO http://blog.vmote.net/
0 Kudos