Find Total Number of Items Count in a PowerShell Array

An array is a basic feature in PowerShell that is designed to store a collection of multiple items. You can iterate the array using ForEach or For loop and access individual items one by one, we can also access individual items by an index of the item. In some cases, we may need to find the total number of items available in the Array object. In this post, we will explore how to find array length or total array items count.

Count property

The Count property returns the number of items count in the array.

$Array = @('One','Two','Three','Four')
$Array.Count
#Output: 4

Length property

The Length property also returns the total items count in the array. In PowerShell, the Count property is a reference to the Length property.

$Array = @('One','Two','Three','Four')
$Array.Length
#Output: 4
Advertisement

Leave a Comment