UBound
Definition: Returns the largest available subscript for the indicated dimension of an array.
There are at least two ways to determine the index number of the last item in a Windows PowerShell array. For example, suppose we have the following array:
$a = " a","b","c","d","e"
With a 5-item array the last item has an index number of 4 (because the first item in the array is actually item 0). But how do we knowthat? One way is to use the GetUpperBound ( )method. This command returns the upper bound for the first dimension (i.e., dimension 0) in the array $a:
$
a.getupperbound
(0)
You can also get the same results by subtracting one from the array’s Lengthproperty:
$a.length-1
When you run either command you should get the following:
4