I can't get that constructor to work either. This however seems to work:

# $temp = Get-ResourceFiles
$resourceFiles = New-Object System.Collections.ArrayList($null)
$resourceFiles.AddRange($temp)

You can also pass an integer in the constructor to set an initial capacity.

What do you mean when you say you want to enumerate the files? Why can't you just filter the wanted values into a fresh array?

Edit:

It seems that you can use the array constructor like this:

$resourceFiles = New-Object System.Collections.ArrayList(,$someArray)

Note the comma. I believe what is happening is that when you call a .NET method, you always pass parameters as an array. PowerShell unpacks that array and passes it to the method as separate parameters. In this case, we don't want PowerShell to unpack the array; we want to pass the array as a single unit. Now, the comma operator creates arrays. So PowerShell unpacks the array, then we create the array again with the comma operator. I think that is what is going on.

Answer from dan-gph on Stack Overflow
🌐
Adam the Automator
adamtheautomator.com › powershell-array
PowerShell Arrays, ArrayLists & Collections: Best Practices
PS51> $MyArrayList = New-Object ... the elements at creation time or add them ad-hoc. To add elements to an existing collection, you can use the += operator or the Add method....
Published   April 22, 2025
🌐
SPGuides
spguides.com › powershell-arraylist
PowerShell ArrayList [Create and Use]
March 26, 2025 - If you have an existing array and want to convert it to an ArrayList, you can use the AddRange() method. Here’s an example and the complete PowerShell:
Discussions

How to create an ArrayList from an Array in PowerShell? - Stack Overflow
To get an instance this would actually ... but I didn't check if powershell always uses ArrayList as the instance of array. 2016-02-22T23:51:03.41Z+00:00 ... @npjohns PowerShell arrays are actually .NET arrays. (The @().Add method fails.)... More on stackoverflow.com
🌐 stackoverflow.com
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
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
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
🌐
Vexx32
vexx32.github.io › 2020 › 02 › 15 › Building-Arrays-Collections
Building Arrays and Collections in PowerShell
Why would we use this over ArrayList? In PowerShell there isn't a massive difference here, but for me personally it comes down to a few things. You can create a List that only stores a specific type, which means you can catch mistakes earlier. Adding other types of items to that list will either have them converted to the List's designated type, or will throw an error stating that it was the wrong type. Using the Add() method on List<T> doesn't create incidental output like ArrayList's Add() method does, so you have less chance to miss things and pollute your output stream.
🌐
SharePoint Diary
sharepointdiary.com › sharepoint diary › powershell › powershell tutorials › powershell arraylist – a beginners guide!
PowerShell ArrayList - A Beginners Guide! - SharePoint Diary
September 30, 2025 - These methods include adding elements, removing elements, sorting, and searching, among others. PowerShell ArrayList and Array are two collection types that can be used to store and manipulate data in PowerShell.
🌐
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
If the only data that you have in your array is strings, then also take a look at using StringBuilder. It's almost the same thing but has some methods that are just for dealing with strings. The StringBuilder is specially designed for performance. It's common to see people move to ArrayList from arrays.
🌐
| How
pipe.how › new-arraylist
PowerShell Collections: ArrayList | How
January 17, 2020 - PipeHow:\Blog> $ArrayList = New-Object System.Collections.ArrayList PipeHow:\Blog> $ArrayList = [System.Collections.ArrayList]::new() 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.
Find elsewhere
🌐
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
🌐
IDERA
idera.com › home › using efficient lists in powershell
Using Efficient Lists in PowerShell | IDERA
April 22, 2025 - # use a dynamically extensible array $array = [System.Collections.ArrayList]@() 1..100000 | ForEach-Object { # use the Add() method instead of "+=" # discard the return value provided by Add() $null = $array.Add("adding $_") } $array.count
🌐
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.
🌐
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.
🌐
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 ...
🌐
Microsoft Certified Professional Magazine
mcpmag.com › articles › 2019 › 04 › 10 › managing-arrays-in-powershell.aspx
Managing Arrays in PowerShell -- Microsoft Certified Professional Magazine Online
Remove() methods to add or remove items from the array. I'm using the term "array" loosely here. From now on, a PowerShell array and an object of type · System.Collections.ArrayList is one and the same for us.
🌐
Wit IT
witit.blog › array-vs-arraylist-powershell
Array vs ArrayList (PowerShell) - Wit IT - witit
December 22, 2022 - Ouch, nothing but love for all of the PowerShell scripting politicians out there. I’m sure you’re the exception to this! Anyway, let’s look at an ArrayList and how it differs from our usual Array. First, let’s look at an easy way to define it: [Collections.ArrayList]$ArrayList = @('thing1','thing2') Secondly, let’s check the type with the GetType() method...
🌐
Powershell Commands
powershellcommands.com › powershell-array-list
Mastering PowerShell Array List: A Quick Guide
June 14, 2024 - Here’s how you do it: $arrayList = New-Object System.Collections.ArrayList · This line initializes a new instance of an array list, ready for you to add items. Populating your array list is straightforward.
🌐
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
🌐
ScriptRunner
scriptrunner.com › resources › powershell-tips › powershell-array-types
Exploring PowerShell Array Types: A Comprehensive Guide
May 22, 2025 - This example uses a [string[]]: a user can enter ten names, and if a number is accidentally added, PowerShell will automatically convert it to a string: # new empty string array [string[]]$names = @() # let user enter 10 names for ($x=1; $x-le10;$x++) { $names += Read-Host -Prompt "Enter $x. Name" } $names.Count · Whats most important about the last example is the reappearance of the dreaded += problem we previously discussed: how can you use a typed array that can dynamically grow or shrink? [System.Collections.ArrayList] is not typed.
🌐
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 - 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.
🌐
Jonathanmedd
jonathanmedd.net › 2014 › 01 › adding-and-removing-items-from-a-powershell-array.html
Adding and Removing Items from a PowerShell Array - Jonathan Medd's Blog
\[System.Collections.ArrayList\]$ArrayList = $Fruits $ArrayList.GetType() Now if we try the previous add and remove methods we are successful: