# How to get a value from a property named Length instead of the size of the Array

**URL:** <https://forums.powershell.org/t/how-to-get-a-value-from-a-property-named-length-instead-of-the-size-of-the-array/14546>\
**Category:** PowerShell Help\
**Created:** [June 17, 2020, 5:02am UTC](https://forums.powershell.org/t/how-to-get-a-value-from-a-property-named-length-instead-of-the-size-of-the-array/14546 "2020-06-17T05:02:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mraol](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@mraol](https://forums.powershell.org/u/mraol)\
**Post date:** [June 17, 2020, 5:02am UTC](https://forums.powershell.org/t/how-to-get-a-value-from-a-property-named-length-instead-of-the-size-of-the-array/14546/1 "2020-06-17T05:02:15Z")

</div>

An interesting situation I ran into.

Working with VMware PowerCLI to gather performance metrics from vCenter. One of the checks I need to do is to find out the statistics collection level. That returns an array and part of which looks like below. As you may notice that it has a property called “Length” (that should have been named “Duration” but that is beside the point 🙂 ) and I need to use the values contained in it.

```
PS C:\Temp> $perfMgr.HistoricalInterval | ft 

Key SamplingPeriod Name Length Level Enabled
--- -------------- ---- ------ ----- -------
1 300 Past day 86400 1 True
2 1800 Past week 604800 1 True
3 7200 Past month 2592000 1 True
4 86400 Past year 31536000 1 True
```

I am trying to get to the values contained within the property Length (eg: 86400). Since it shares a name with the property that gives me how big the Array is (in this case 4) I always get that instead of the value in the property Length. Please see below.

```
PS C:\Temp> $perfMgr.HistoricalInterval.SamplingPeriod[0] 
300
PS C:\Temp> $perfMgr.HistoricalInterval.Name[0] 
Past day
PS C:\Temp> $perfMgr.HistoricalInterval.Length[0] 
4
PS C:\Temp>
```

How do I get the value I am looking for?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [June 17, 2020, 5:31am UTC](https://forums.powershell.org/t/how-to-get-a-value-from-a-property-named-length-instead-of-the-size-of-the-array/14546/2 "2020-06-17T05:31:38Z")

</div>

The array index is in the wrong place. You are getting the object length’s first item. The reason it’s working for your other is Powershell is returning an array containing the ‘SamplingPeriod’ and you are getting the first item in the array.

```
$temp = @"
Key,SamplingPeriod,Name,Length,Level,Enabled
1,300,Past day,86400,1,True
2,1800,Past week,604800,1,True
3,7200,Past month,2592000,1,True
4,86400,Past year,31536000,1,True
"@ | ConvertFrom-Csv

$temp

$temp[0].Length
$temp[0] | Select -ExpandProperty Length
```

Output:

```
PS C:\Users\rasim> $temp[0].Length

86400

PS C:\Users\rasim> $temp[0] | Select -ExpandProperty Length
86400

PS C:\Users\rasim> $temp[0].SamplingPeriod
300
```

---

<div class="post-metadata">

**Author:** ![mraol](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@mraol](https://forums.powershell.org/u/mraol)\
**Post date:** [June 17, 2020, 5:40am UTC](https://forums.powershell.org/t/how-to-get-a-value-from-a-property-named-length-instead-of-the-size-of-the-array/14546/3 "2020-06-17T05:40:43Z")

</div>

You are my Hero Rob !!

Thank you!

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/how-to-get-a-value-from-a-property-named-length-instead-of-the-size-of-the-array/14546/4 "2024-05-16T20:29:21Z")

</div>


