VMware Cloud Community
mark_chuman
Hot Shot
Hot Shot
Jump to solution

Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.

Just hit this one and I welcome any other insight.

Here is the code ----

$Cluster = "clustername"

$esxpass = "password"

$esxcheck = foreach ($vmhost in get-cluster -name $Cluster | get-vmhost | select Name) `

{Connect-VIServer -Server $vmhost.name -User root -Password $esxpass}

foreach ($vmhost in get-cluster -name $Cluster | get-vmhost | select Name) `

{disconnect-viserver $vmhost.name -confirm:$false}

Works fine on a 16 node cluster, but fails with the error on a 31 node cluster  :smileycry:

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Are you sure of that code ?

What exactly are you trying to do ?


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

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

Are you sure of that code ?

What exactly are you trying to do ?


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

0 Kudos
mark_chuman
Hot Shot
Hot Shot
Jump to solution

yeah, the code is hardened.  i use it in a VC migration script that we've used hundreds of times.  this portion is going out and checking root password before moving on with the actual migration.  we just now are using it on really large clusters.  up until now it's only been used on 16 node clusters, max.

0 Kudos
mark_chuman
Hot Shot
Hot Shot
Jump to solution

I adjusted the code to this and we're good.  I'll have to look through the rest of the overall script for similar items.

foreach ($vmhost in get-cluster -name $Cluster | get-vmhost | select Name) `

{Connect-VIServer -Server $vmhost.name -User root -Password $esxpass

disconnect-viserver $vmhost.name -confirm:$false}

*I know the format is horrible Smiley Happy

0 Kudos