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
Using a PowerShell ArrayList is ... with PowerShell. The ArrayList class is part of the System.Collections namespace within .NET. By creating a new object of this type you can then store objects within an ArrayList. 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 ...
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:
🌐
SharePoint Diary
sharepointdiary.com › sharepoint diary › powershell › powershell tutorials › powershell arraylist – a beginners guide!
PowerShell ArrayList - A Beginners Guide! - SharePoint Diary
September 30, 2025 - 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 ...
🌐
LazyAdmin
lazyadmin.nl › home › how to use powershell array – complete guide
How to Use PowerShell Array - Complete Guide — LazyAdmin
January 19, 2023 - For example, to remove Banana from the $fruits array, we copy the array and use the Where-Object cmdlet to filter out the Banana: $fruits = $fruits | Where-Object {$_ -ne "Banana"} There is a better way to add or remove items from an array. For this, we will need to use the PowerShell ArrayList, which is available in the ‘System.Collections.ArrayList’ class.
🌐
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 ...
🌐
The Tech Platform
thetechplatform.com › post › how-to-create-and-use-powershell-arraylist
How to create and use PowerShell ArrayList
May 18, 2023 - In this example, the Sort() method is called on the ArrayList $myArrayList, resulting in the elements being sorted alphabetically. After sorting, the ArrayList will contain "Apple", "Banana", and "Orange".
🌐
ScriptRunner
scriptrunner.com › blog-admin-architect › 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.
Find elsewhere
🌐
Vexx32
vexx32.github.io › 2020 › 02 › 15 › Building-Arrays-Collections
Building Arrays and Collections in PowerShell
The main type of collection in use in PowerShell is the humble Array, at least in terms of what is often available directly from a script. Behind the murky curtain, PowerShell actually utilises the System.Collections.ArrayList type quite heavily in its pipeline processor.
🌐
Wit IT
witit.blog › array-vs-arraylist-powershell
Array vs ArrayList (PowerShell) - Wit IT - witit
December 22, 2022 - So now that we know some of the key differences and a common way that ArrayLists can trip us up if you’re used to using Arrays, let’s talk efficiency. First, let’s build some data to test with. My WinSxS folder has 15k child items. For this example, let’s compare the speed of adding each name to an Array vs Arraylist using Measure-Command:
🌐
Scriptwizards
scriptwizards.net › home › exploring powershell arrays: a comprehensive guide
Exploring PowerShell Arrays: A Comprehensive Guide - ScriptWizards.Net
June 13, 2024 - # Creating an ArrayList $arrayList = [System.Collections.ArrayList]::new() # Adding elements $arrayList.Add(1) | Out-Null $arrayList.Add(2) | Out-Null $arrayList.Add(3) | Out-Null # Accessing elements Write-Output $arrayList[1] # Outputs: 2 # Removing an element $arrayList.Remove(2) # Display the array $arrayList · PowerShell arrays are powerful tools for managing collections of data.
🌐
| 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.
🌐
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.
🌐
SPGuides
spguides.com › powershell-array
PowerShell Array - Complete Tutorial
May 6, 2025 - Here is an example. $customerIDs = [System.Collections.ArrayList]@(1001, 1002, 1003) $customerIDs.Add(1004) # Returns the index where the item was added · Using ArrayList provides better performance for frequently modified collections. Unlike standard PowerShell arrays, ArrayList is designed for efficient additions and removals.
🌐
Java2Blog
java2blog.com › home › powershell › powershell array › convert array to arraylist in powershell
Convert Array to ArrayList in PowerShell [2 Ways] - Java2Blog
April 16, 2023 - For example, we add an element to the ArrayList using the Add() method, remove the first element with the Remove() method, sort the elements using the Sort() method, and get the element count with the Count property.
🌐
Netwrix
blog.netwrix.com › home › resources › how to use powershell arrays
How to Use PowerShell Arrays | Netwrix
December 13, 2024 - The size of an array in PowerShell is immutable once it is defined. However, the operator += enables you to create a new array by appending items to an existing array — essentially creating a new combined array. ... For large arrays or frequent additions, use of += can be a performance concern, since every time use it, a new array is created, the old elements are copied over and the new element is added to the end. In those cases, you may want to use an ArrayList...
🌐
Powershell Commands
powershellcommands.com › powershell-array-list
Mastering PowerShell Array List: A Quick Guide
June 14, 2024 - A PowerShell array list is a dynamic collection that allows you to store and manipulate a list of items efficiently, and you can create one using the following code snippet: $arrayList = New-Object System.Collections.ArrayList $arrayList.Ad...