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
🌐
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
Discussions

How to create an ArrayList from an Array in PowerShell? - Stack Overflow
I've got a list of files in an array. I want to enumerate those files, and remove specific files from it. Obviously I can't remove items from an array, so I want to use an ArrayList. But the follow... More on stackoverflow.com
🌐 stackoverflow.com
Use array of strings for comparing in Where-Object in PowerShell - Stack Overflow
I have a user list of Active Directory that I retrieve this way: $users = Get-AdUser -Filter {(Enabled -eq "True" )} -Properties Description The problem is that I have a specific set of users tha... More on stackoverflow.com
🌐 stackoverflow.com
Powershell find value in arraylist - Stack Overflow
I hope you can help me out. I work with two ArrayLists: array1 is filled with log.csv (contains header and logon-data, values of column 'pc' are unique). It's defined as ArrayList because I want t... More on stackoverflow.com
🌐 stackoverflow.com
Using Where-Object to filter one array with another.
To answer your question directly: $filterModels = 'Model1', 'Model2', 'Model3' $filtered = $computers | Where-Object {$_.Model -in $filterModels} Another fun way is to add a calculated property to $computers. This code adds a new boolean property DoesModelMatch , which you can then filter on in similar fashion: $filterModels = 'Model1', 'Model2', 'Model3' $computers = $computers | Select-Object *,@{n='DoesModelMatch'; e={$_.Model -in $filterModels}} $computers | Where-Object {$true -eq $_.DoesModelMatch} More on reddit.com
🌐 r/PowerShell
13
25
September 19, 2022
🌐
SharePoint Diary
sharepointdiary.com › sharepoint diary › powershell › powershell tutorials › powershell arraylist – a beginners guide!
PowerShell ArrayList - A Beginners Guide! - SharePoint Diary
September 30, 2025 - The ArrayList is a generic List collection type found in the System.Collections.ArrayList class. You can store ordered collections of any object type, like strings, numbers, custom objects, etc. Unlike the traditional PowerShell array, ArrayList can grow and shrink dynamically, making it ideal for situations where the number of elements is not known in advance or needs to change over time.
🌐
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 ...
🌐
| 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
🌐
Enterprise DNA
blog.enterprisedna.co › powershell-arraylist
Powershell ArrayList: How to Build Better Scripts – Master Data Skills + AI
The System.Collections.ArrayList class is one such class within this namespace. By utilizing PowerShell ArrayLists and the classes available in the System.Collections namespace, you gain access to a powerful set of tools for organizing, processing, and manipulating data in your scripts.
🌐
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
🌐
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.
🌐
IDERA
idera.com › home › using efficient lists in powershell
Using Efficient Lists in PowerShell | IDERA
April 22, 2025 - Learn how to handle dynamic lists efficiently in PowerShell using System. Collections.ArrayList and generic lists instead of default object.
🌐
Wit IT
witit.blog › array-vs-arraylist-powershell
Array vs ArrayList (PowerShell) - Wit IT - witit
December 22, 2022 - So let’s say I only wanted to add files and folders with the word SETUP to an array. There are 2 files that contain the word Setup in the name. Before adding them to an Array or an ArrayList, let’s just count ’em and check 0 in the index:
🌐
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.
🌐
Reddit
reddit.com › r/powershell › what is the recommended way to declare an arraylist?
r/PowerShell on Reddit: what is the recommended way to declare an ArrayList?
June 29, 2016 -

howdy y'all,

i was playing around with arraylists and accidentally used two different ways to declare them. lookee ...

[System.Collections.ArrayList]$1st_AL = @()
$2nd_AL = [System.Collections.ArrayList]@()

both seem to work fine. so, i wonder which is the most readable or otherwise "best"? i'm rather partial to the 2nd one since - to me - it seems more readable.

take care,
lee


-ps
here's the ones so far ...

[System.Collections.ArrayList]$1st_AL = @()    
$2nd_AL = [System.Collections.ArrayList]@()    
$3rd_AL = [System.Collections.ArrayList]::new()    
$4th_AL = New-Object System.Collections.ArrayList($Null)    
$5th_AL = New-Object System.Collections.ArrayList(,(1..10))    
$6th_AL = New-Object System.Collections.ArrayList    

i still like the way the 2nd one reads, tho. [grin]
lee-


-pps
it looks like the 6th one is the best combo of safety and readability. the 2nd one leaves you open to unintended type conversion. ick!

thank you all for your input! [grin]
lee-

🌐
PowerShell Forums
forums.powershell.org › powershell help
Powershell Array list - PowerShell Help - PowerShell Forums
April 27, 2020 - I am looking for help in arrays and forloop for a powershell script. I have list of domains in first array I need to reiterate get-computer command and give searchbase from my second array. The first index in domains list is the input for searchbase . We have 10 domains which I need to run ...
🌐
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.
🌐
Powershellexplained
powershellexplained.com › 2018-10-15-Powershell-arrays-Everything-you-wanted-to-know
Everything you wanted to know about arrays - Powershell
October 15, 2018 - ArrayList · Generic List · List[PSObject] Remove() More collections · Other nuances · Pre-sized arrays · Multiplying arrays · Initialize with 0 · Nested arrays · Write-Output -NoEnumerate · Return an array · Anything else? I am going to start with a basic technical description of what arrays are and how they are used by most programming languages before I shift into the other ways PowerShell makes use of them.