Automation

 View Only
  • 1.  Load Balance LUN Paths, Where-Object error

    Posted Jun 15, 2009 06:55 PM

    Greetings,

    I have started modifying the script from:

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

    to fit our enviroment. We have our utility LUNs labeled similar to out VM LUNs, but they do not have the same number of paths. Here is the where-object select statement I am using:

    Script SNIP:

    $luns = $VMHost|get-scsilun -luntype disk|

    where-object {$_.ConsoleDeviceName -like "/vmfs/devices/disks/vml*"} |

    where-object {$_.CanonicalName -like "vmhba0:0:*"}|Sort-Object CanonicalName

    $firstLUNPaths = Get-ScsiLunPath $lun[0]

    $numPaths = $firstLUNPaths.Length

    The script work fine on the first host in the cluster, but I recieve this error on each host afterwards:

    Err:

    Unable to index into an object of type VMware.VimAutomation.Client20.Host.ScsiLunImpl.

    At C:\hp\Tools\VM_Tools\Scripts\Pathing\Set_Cluster_SAN_Path_t.ps1:37 char:40

    + $firstLUNPaths = Get-ScsiLunPath $lun[0 <<<< ]

    Line 37 is:

    $firstLUNPaths = Get-ScsiLunPath $lun[0]

    If I remove the portion of the select statement:

    where-object {$_.CanonicalName -like "vmhba0:0:*"}

    The error goes away. Since this is the portion of the select statement that gets the VM LUNs I really would like this to work.

    Thanx in advance!

    Kevin



  • 2.  RE: Load Balance LUN Paths, Where-Object error
    Best Answer

    Posted Jun 15, 2009 08:01 PM

    Are you sure that $lun is an array when you get the error ?

    Could be that there is only 1 ScsiLunImpl object. Hence the index error.

    You can try asking the type of the $lun variable

    $luns = $VMHost|get-scsilun -luntype disk|
    where-object {$_.ConsoleDeviceName -like "/vmfs/devices/disks/vml*"} |
    where-object {$_.CanonicalName -like "vmhba0:0:*"}|Sort-Object CanonicalName
    
    ($lun.gettype()).Name
    
    $firstLUNPaths = Get-ScsiLunPath $lun[0]
    $numPaths = $firstLUNPaths.Length
    

    This will say "object[]" when it's an array but "ScsiLunImpl" when it's a single object.

    An easy way to solve this would be to make it an array even when there is only 1 object

    $luns = @($VMHost|get-scsilun -luntype disk|
    where-object {$_.ConsoleDeviceName -like "/vmfs/devices/disks/vml*"} |
    where-object {$_.CanonicalName -like "vmhba0:0:*"}|Sort-Object CanonicalName)
    $firstLUNPaths = Get-ScsiLunPath $lun[0]
    $numPaths = $firstLUNPaths.Length
    



  • 3.  RE: Load Balance LUN Paths, Where-Object error

    Posted Jun 16, 2009 10:54 AM

    LucD, I attempted the change you suggested and recieved the same error.

    I am new to powershell scripting, I am not sure what you are refering to when you say "You can try asking the type of the $lun variable"

    Thanx!



  • 4.  RE: Load Balance LUN Paths, Where-Object error

    Posted Jun 16, 2009 11:03 AM

    Just noticed: in line 1 you assign the value to a variable called $luns.

    And in line 4 you reference a variable called $lun.

    Is that a typo in your script SNIP or is that perhaps the cause of the problem.



  • 5.  RE: Load Balance LUN Paths, Where-Object error

    Posted Jun 16, 2009 11:51 AM

    Good catch... Yes that was an actual typo in the script. I went back to the original script before we found our issue witht he utility LUNs.

    I had modified the variable during testing processes.

    Now using the array suggestion works great!!

    Thank you for your time!!