Yes, you create an empty array then use it to initialize the variable. Two other ways (System not needed as its namespace is already loaded): [Collections.ArrayList]$list = @() $list = [Collections.ArrayList]::new() New-Object is useful when you need -ComObject, or to dynamically create a type (typename stored as a string that you may not know when writing). It is the 'older' method before powershell had classes built-in. Also, if you create an 'untyped' variable from a cast, you can change its type later on. The first example I posted enforces the type for that variable, it can only be an arraylist. I recommend using the generic types where you can specify the type: [Collections.Generic.List[String]]$list = @() $list = [Collections.Generic.List[Int]]::new() Also save some typing and use a namespace: using namespace System.Collections.Generic [List[String]]$list = @() $list = [List[Int]]::new() And for speed (enumeration access), if the items are unique, try a HashSet: using namespace System.Collections.Generic [HashSet[String]]$list = @() $list = [HashSet[Int]]::new() You should be measuring speed on insertion/removal and access for real world speed tests. And you'll definitely see different results when you go past milestones like 10, 1000, 10000 items (generics are tailored to large datasets). Answer from chris-a5 on reddit.com
🌐
Vexx32
vexx32.github.io › 2020 › 02 › 15 › Building-Arrays-Collections
Building Arrays and Collections in PowerShell
Any uncaptured output will then be funneled into that variable and stored as [object[]] (an array of objects) in the variable. Because this utilises the built-in PowerShell pipeline (which, remember, uses ArrayList to handle output), there is no additional overhead of creating another type of collection here.
🌐
SharePoint Diary
sharepointdiary.com › sharepoint diary › powershell › powershell tutorials › powershell arraylist – a beginners guide!
PowerShell ArrayList - A Beginners Guide! - SharePoint Diary
September 30, 2025 - This can help reduce the number of memory allocations and improve the performance of your script. For example, if you expect your ArrayList to have approximately 100 elements, you can create it like this: ... This creates an empty array list with 100 elements. Alternatively, you can create an ArrayList by casting a comma-separated list to [System.Collections.ArrayList]: ... Both methods will create a new ArrayList object, which you can then use to store and manipulate data in your PowerShell script.
Discussions

Two ways of creating a new System.Collections.ArrayList object, what's the difference?
Yes, you create an empty array then use it to initialize the variable. Two other ways (System not needed as its namespace is already loaded): [Collections.ArrayList]$list = @() $list = [Collections.ArrayList]::new() New-Object is useful when you need -ComObject, or to dynamically create a type (typename stored as a string that you may not know when writing). It is the 'older' method before powershell had classes built-in. Also, if you create an 'untyped' variable from a cast, you can change its type later on. The first example I posted enforces the type for that variable, it can only be an arraylist. I recommend using the generic types where you can specify the type: [Collections.Generic.List[String]]$list = @() $list = [Collections.Generic.List[Int]]::new() Also save some typing and use a namespace: using namespace System.Collections.Generic [List[String]]$list = @() $list = [List[Int]]::new() And for speed (enumeration access), if the items are unique, try a HashSet: using namespace System.Collections.Generic [HashSet[String]]$list = @() $list = [HashSet[Int]]::new() You should be measuring speed on insertion/removal and access for real world speed tests. And you'll definitely see different results when you go past milestones like 10, 1000, 10000 items (generics are tailored to large datasets). More on reddit.com
🌐 r/PowerShell
11
27
April 7, 2023
Adding arrays to arraylists
I have an object which is of type {system.collections.arraylist] To add a single element I can use the Add method but to add an array I have to use the ‘+=’ method. Does anyone have a technical explanation for this as ‘+=’ doesnt seem to be in the microsoft doco below: I am also assuming ... More on forums.powershell.org
🌐 forums.powershell.org
7
0
July 11, 2022
arrays - PowerShell: Passing an ArrayList of Objects into another Script as an Argument - Stack Overflow
I am trying to pass an ArrayList that contains objects into another PowerShell script to execute something further. The error message that I am receiving is: "Cannot process argument transfor... More on stackoverflow.com
🌐 stackoverflow.com
When to use array vs array list vs list
Array: When you don't need to dynamically add items to a collection outside a loop. ArrayList: Never. Generic list: When you do need to dynamically add items to a collection outside a loop. Arrays are the default output type in PowerShell. Whenever you run an expression that outputs multiple items you will get a System.Object array. An obvious example of this would be running a command like $Data = Get-ChildItem, a less obvious example would be the output from a loop: $Data = foreach ($Item in $Collection) or even an if/else statement $Data = if ($true) {"Hello"} else {"Goodbye"}. If the expression only outputs a single item then the array will get unwrapped and you just get the raw value like a string. Because it's the default behavior you don't really need to think about it but if you need more complex stuff that can't be handled by simply putting $Var = in front of an expression then you need a list. An easy example to demonstrate is an odd/even list: $Odd = [System.Collections.Generic.List[int]]::new() $Even = [System.Collections.Generic.List[int]]::new() foreach ($Number in 1..10) { if ($Number % 2 -eq 0) { $Even.Add($Number) } else { $Odd.Add($Number) } } More on reddit.com
🌐 r/PowerShell
40
33
April 25, 2022
🌐
SPGuides
spguides.com › powershell-arraylist
PowerShell ArrayList [Create and Use]
March 26, 2025 - An ArrayList in PowerShell is a dynamic collection that allows you to store and manipulate a list of objects.
🌐
Adam the Automator
adamtheautomator.com › powershell-array
PowerShell Arrays, ArrayLists & Collections: Best Practices
Below you can see that you need to explicitly create an ArrayList object using the New-Object cmdlet or by casting a standard array to an ArrayList object. Notice that in this case the BaseType is an object whereas the above examples have BaseTypes of Arrays which exhibit inheritance from the Object class. Ultimately, PowerShell is providing access to the .NET type system.
Published   April 22, 2025
🌐
Reddit
reddit.com › r/powershell › two ways of creating a new system.collections.arraylist object, what's the difference?
r/PowerShell on Reddit: Two ways of creating a new System.Collections.ArrayList object, what's the difference?
April 7, 2023 -

I've come across two ways of creating a new System.Collections.ArrayList object:

$arrA = New-Object System.Collections.ArrayList
$arrB = [System.Collections.ArrayList]@() 

I have two questions:

  1. for arrB, if I'm reading this right, @() is creating an empty array and then it's being cast into [System.Collections.ArrayList]?

  2. Working with the created object is the same for me either way, but are there any differences I may be missing?

I made a quick test and casting was faster, but the difference is only noticeable when creating new arrays reaches the hundreds of thousands to millions (tested on an old A10-7870k). Doesn't really matter when I'm creating one array, but I thought it was mildly interesting.

$max = 100000
$ticksStart = (Get-Date).Ticks
for ($i = 0; $i -lt $max; $i++)
{
	$arrA = New-Object System.Collections.ArrayList
}
$ticksEnd = (Get-Date).Ticks
Write-Host 'arrA (ticks)	: ' ($ticksEnd - $ticksStart)

$ticksStart = (Get-Date).Ticks
for ($i = 0; $i -lt $max; $i++)
{
	$arrB = [System.Collections.ArrayList]@()
}
$ticksEnd = (Get-Date).Ticks
Write-Host  'arrB (ticks)	: ' ($ticksEnd - $ticksStart)
arrA (ticks)	:  64310000
arrB (ticks)	:  3170000
🌐
Enterprise DNA
blog.enterprisedna.co › powershell-arraylist
Powershell ArrayList: How to Build Better Scripts – Master Data Skills + AI
An ArrayList in PowerShell provides a convenient way to store various data types, offering more flexibility compared to standard arrays which are strongly typed and can only store specific types of elements. To create and work with an ArrayList in PowerShell, you can use the New-Object command or call the constructor of the System.Collections.ArrayList class.
🌐
PowerShell Forums
forums.powershell.org › powershell help
Adding arrays to arraylists - PowerShell Help - PowerShell Forums
July 11, 2022 - I have an object which is of type {system.collections.arraylist] To add a single element I can use the Add method but to add an array I have to use the ‘+=’ method. Does anyone have a technical explanation for this as ‘+=’ doesnt seem to be in the microsoft doco below: I am also assuming ...
Find elsewhere
🌐
| How
pipe.how › new-arraylist
PowerShell Collections: ArrayList | How
January 17, 2020 - One uses New-Object and the other calls the constructor of the class. You’re free to use whichever you prefer, although when sharing scripts it might be worth considering that people that are just getting into PowerShell and learning commands may be confused at the second one. So far it’s nothing too exciting, but let’s have a look at the type and members of it to see if we can spot some differences to a normal Array. PipeHow:\Blog> $ArrayList.GetType() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True ArrayList System.Object
🌐
SS64
ss64.com › ps › syntax-arrays.html
Create and use PowerShell Arrays
$countries = New-Object System.Collections.ArrayList $countries.Add('India') > $null $countries.Add('Montenegro') > $null · To retrieve an element, specify its number, PowerShell automatically numbers the array elements starting at 0. ... Think of the index number as being an offset from the staring element.
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › scripting › learn › deep-dives › everything-about-arrays
Everything you wanted to know about arrays - PowerShell | Microsoft Learn
Arrays and the PowerShell pipeline are meant for each other. This is one of the simplest ways to process over those values. When you pass an array to a pipeline, each item inside the array is processed individually. PS> $data = 'Zero','One','Two','Three' PS> $data | ForEach-Object {"Item: [$PSItem]"} Item: [Zero] Item: [One] Item: [Two] Item: [Three]
🌐
Reddit
reddit.com › r/powershell › when to use array vs array list vs list
r/PowerShell on Reddit: When to use array vs array list vs list
April 25, 2022 - ArrayList: Never. Generic list: When you do need to dynamically add items to a collection outside a loop. Arrays are the default output type in PowerShell. Whenever you run an expression that outputs multiple items you will get a System.Object array. An obvious example of this would be running a command like $Data = Get-ChildItem, a less obvious example would be the output from a loop: $Data = foreach ($Item in $Collection) or even an if/else statement $Data = if ($true) {"Hello"} else {"Goodbye"}. If the expression only outputs a single item then the array will get unwrapped and you just get the raw value like a string.
🌐
Varonis
varonis.com › blog › powershell-array
PowerShell Array Guide: How to Use and Create
June 9, 2022 - Here, we can use the default .Net constructor to create a new ArrayList, and then using the -Add operator to add items to it. The [void] operator is there because sometimes these commands throw out strange outputs that can mess with the code. These are the most common array types in PowerShell, but there are a few others.
Top answer
1 of 3
3

The challenge is to add a copy of the $fooChild [pscustomobject] instance you're re-using every time you add to the list with .Add() (if you don't use a copy, you'll end up with all list elements pointing to the same object).

However, you cannot clone an existing [pscustomobject] (a.k.a [psobject]) instance with New-Object PSObject -Property.

One option (PSv3+) is to define the reusable $fooChild as an ordered hashtable instead, and then use a [pscustomobject] cast, which implicitly creates a new object every time:

$fooCollection = [PSCustomObject] @{ fooChildrenList = New-Object Collections.ArrayList } 

# Create the reusable $fooChild as an *ordered hashtable* (PSv3+)
$fooChild = [ordered] @{ childName = ''; childAge = -1 }

# Create 1st child and add to list with [pscustomobject] cast
$fooChild.childName = 'Betsy'; $fooChild.childAge = 6
$null = $fooCollection.fooChildrenList.Add([pscustomobject] $fooChild)

# Create and add another child.
$fooChild.childName = 'Rolf'; $fooChild.childAge = 10
$null = $fooCollection.fooChildrenList.Add([pscustomobject] $fooChild)

# Output the children
$fooCollection.fooChildrenList

Note the $null = ..., which suppresses the typically unwanted output from the .Add() method call.

The above yields:

childName childAge
--------- --------
Betsy            6
Rolf            10

A slightly more obscure alternative is to stick with $fooChild as a [pscustomobject] instance and call .psobject.Copy() on it to create a clone.


ArcSet's helpful answer provides a more modular solution that creates new custom-object instances on demand via a helper function.


Finally, in PSv5+ you could define a helper class:

$fooCollection = [PSCustomObject] @{ fooChildrenList = New-Object Collections.ArrayList } 

# Define helper class
class FooChild {
  [string] $childName
  [int]    $childAge
}

# Create 1st child and add to list with [pscustomobject] cast
$null = $fooCollection.fooChildrenList.Add([FooChild] @{ childName = 'Betsy'; childAge = 6 })

# Create and add another child.
$null = $fooCollection.fooChildrenList.Add([FooChild] @{ childName = 'Rolf'; childAge = 10 })

# Output the children
$fooCollection.fooChildrenList

Note how instances of [FooChild] can be created by simply casting a hashtable that has entries matching the class property names.

2 of 3
2

Well im not sure what issue you are getting it works fine for me

function New-Child([string]$Name, [int]$Age){
    $Child = New-Object -TypeName PSobject
    $Child | Add-Member -Name childAge -MemberType NoteProperty -Value $age -PassThru | 
    Add-Member -Name childName -MemberType NoteProperty -Value $name
    return $child
}

$fooCollection = [PSCustomObject] @{fooName=""; fooUrl=""; fooChildrenList = New-Object System.Collections.ArrayList} 

$fooCollection.fooName = "foo-a-rama"
$fooCollection.fooUrl = "https://1.2.3.4"
$fooCollection.fooChildrenList.Add((New-Child -Name "Betty" -Age 9)) | Out-Null
$fooCollection.fooChildrenList.Add((New-Child -Name "Ralf" -Age 15)) | Out-Null

$fooCollection.fooName
$fooCollection.fooUrl
foreach ($fooChild in $fooCollection.fooChildrenList)
{
    "  " + $fooChild.childName + " " + $fooChild.childAge
}

output

foo-a-rama
https://1.2.3.4
  Betty 9
  Ralf 15
🌐
Netwrix
netwrix.com › home › resources › blog › how to use powershell arrays
How to Use PowerShell Arrays | Netwrix
December 13, 2024 - IntroductionCreating an Array of ObjectsCreating an Array with Just One ElementCreating an Empty ArrayCreating a Strongly Typed ArrayCreating a Multidimensional Array (Matrix)Comparing, Grouping, Selecting and Sorting ArraysLooping through an ArrayUsing a PipelineAdding to an ArrayCreating an ArrayListRemoving ...
🌐
IDERA
idera.com › home › using efficient lists in powershell
Using Efficient Lists in PowerShell | IDERA
April 22, 2025 - # use a typed list for more efficiency $array = [System.Collections.Generic.List[string]]@() 1..100000 | ForEach-Object { # typed lists support Add() as well but there is no # need to discard a return value $array.Add("adding $_") } $array.count · If you needed a list of integers instead, simply replace the type inside the type name of the generic list: ... Strong type restriction is just a “can”, not a “must”. If you want generic lists to be just as flexible as the ArrayList and accept any type, use the “object” type:
🌐
vGeek
vcloud-lab.com › entries › powershell › create-powershell-array-of-object-in-different-way
Create PowerShell array of object in different way | vGeek - Tales from real IT system Administration environment
$list = New-Object System.Collections.ArrayList #'System.Collections.Generic.List[PSCustomObject]' $list.Add([PSCustomObject]@{Name='Test1'; Value=1}) $list.Add([PSCustomObject]@{Name='Test2'; Value=2}) $list Creating a fixed-size array in PowerShell can be helpful when you know the exact number of elements needed.
🌐
LazyAdmin
lazyadmin.nl › home › how to use powershell array – complete guide
How to Use PowerShell Array - Complete Guide — LazyAdmin
January 19, 2023 - Learn how to create and use an Array in PowerShell. Including add and removing items, using the ArrayList and sorting arrays