It should only taky seconds Get-Content -Path .\netlogon.log | ForEach-Object { if ($_ -match 'NO_CLIENT_SITE:') { ($_ -split ' ')[-1] } } | Sort-Object -Unique Of course this code should run on the same machine where the log file is. Please do not access the log file … Answer from Olaf on forums.powershell.org
🌐
Reddit
reddit.com › r/powershell › has arraylist been deprecated?
r/PowerShell on Reddit: has ArrayList been deprecated?
November 23, 2016 -

howdy y'all,

i vaguely recall seeing a post in this subreddit some time back that said the ArrayList had been deprecated. now i can't find it. [blush] the only things that show up on a net search are a couple of posts aimed at C# from several years ago.

so, am i misremembering things again?

take care,
lee


-ps
found the reason ... but i don't really understand it. lookee ...
ArrayList vs List<> in C# - Stack Overflow

  • http://stackoverflow.com/questions/2309694/arraylist-vs-list-in-c-sharp
    lee-

🌐
| How
pipe.how › new-arraylist
PowerShell Collections: ArrayList | How
January 17, 2020 - This post will look at the first alternative to arrays that one usually encounters: ArrayList. A disclaimer before diving into the ArrayList, however, is that it is deprecated and the recommendation from Microsoft is that it should not be used for any new development.
Discussions

Help Understanding What's Happening
I am trying to use an arraylist instead of the += to add items to an array. Unfortunately in this script I’m not getting the data I’m expecting. This iteration of the script is producing the data (IP addresses) but runs very slow (I know it’s building the array with each addition) #Result ... More on forums.powershell.org
🌐 forums.powershell.org
1
0
July 5, 2022
PowerShell - modifying and comparing dates
Also, powershell - ArrayList .Add vs .AddRange vis-a-vis the Pipeline - Stack Overflow suggests ArrayList is deprecated. Instead, use generic.list More on community.spiceworks.com
🌐 community.spiceworks.com
11
4
March 9, 2021
powershell - Add an array to an array list - Stack Overflow
Well, or they mention [arralylist], which I hear is deprecated, so I am trying to avoid that too. ... If $list is an ArrayLIst it doesn't matter - if, on the other hand $list is a generic collection, it'll generally accept any IEnumerable, including flats arrays, so you can make due with ... More on stackoverflow.com
🌐 stackoverflow.com
ArrayList obsoletion -- do we care?
Ignoring how it is obsoleted the reason I don't recommend ArrayList is because the Add method outputs the index. This means you need to discard the output everytime you do $list.Add() which gets annoying quickly. The List type has a void Add() method so you don't have to worry about that. Aside from that I usually avoid an ArrayList or List and just capture the output into a var and have powershell deal with it all $list = foreach ($foo in $bar) { "Test-$foo" } The main reason I use a List is when I need to add values to multiple lists in the same loop so I can no longer rely on the output stream. More on reddit.com
🌐 r/PowerShell
49
42
July 25, 2024
🌐
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
It's common to see people move to ArrayList from arrays. But it comes from a time where C# didn't have generic support. The ArrayList is deprecated in support for the generic List[]
🌐
Spiceworks
community.spiceworks.com › programming & development
PowerShell - modifying and comparing dates - #11 by gary-m-g - Programming & Development - Spiceworks Community
March 9, 2021 - Also, powershell - ArrayList .Add vs .AddRange vis-a-vis the Pipeline - Stack Overflow suggests ArrayList is deprecated. Instead, use generic.list
🌐
Vexx32
vexx32.github.io › 2020 › 02 › 15 › Building-Arrays-Collections
Building Arrays and Collections in PowerShell
Given the assertion in the documentation, no less, that ArrayList is recommended against, I would assume two things: There is the possibility at any point that the .NET / .NET Core team will eventually deprecate it completely and possibly even remove it from .NET at that point or afterwards.
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 61756527 › add-an-array-to-an-array-list
powershell - Add an array to an array list - Stack Overflow
Well, or they mention [arralylist], which I hear is deprecated, so I am trying to avoid that too. ... If $list is an ArrayLIst it doesn't matter - if, on the other hand $list is a generic collection, it'll generally accept any IEnumerable<T>, including flats arrays, so you can make due with $list.AddRange([string[]]$array), or if your don't know the type parameter: $list.AddRange($array -as "$($list.GetType().GenericTypeArguments[0])[]").
🌐
Reddit
reddit.com › r/powershell › arraylist obsoletion -- do we care?
r/PowerShell on Reddit: ArrayList obsoletion -- do we care?
July 25, 2024 -

I'm fully aware that ArrayList is not recommended for new development. That being said, do you still use it when you are writing PowerShell? I wish I could add a Poll to solicit the responses more easily, but Poll option is greyed out.

I've been roasted for using it before, but it's just so much more familiar and convenient to instantiate, for me.

[System.Collections.ArrayList]$list = @()

Slim and sexy, concise, looks like other PS syntax I'm used to.

[System.Collections.Generic.List[object]]::new()

Newfangled, unwieldy, uses C# constructor, ugly. Requires me to think about what types I'll have in my list. Smug.

(Obviously I'm feeling a little silly here / tongue in cheek, but I really do feel like I just don't want to bother getting used to the new way.)

EDIT: Some of the advice is helpful, but mostly what I was hoping to find out was whether I'm alone or whether you all use ArrayList. It's kind of like, I know I'm supposed to drink 8 glasses of water today, but I have a suspicion that few people actually do. So that's why I'm asking.

FINAL EDIT: After seeing that most people don't use ArrayLists anymore, I think I'm going to learn Lists and do things properly. Turns out I'm in the minority, at least on this sub. Thanks for the discussion everyone.

🌐
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.
🌐
GitHub
github.com › PowerShell › PowerShell › issues › 17362
ArrayList is not accepted as a "Mandatory" parameter to a function if one of its elements is $null · Issue #17362 · PowerShell/PowerShell
May 17, 2022 - I found, after half an hour of pure confusion, that an instance of System.Collections.ArrayList is not accepted as a parameter that is marked as Mandatory if one of its elements is $null.
Published   May 17, 2022
Author   davidreis97
🌐
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.
🌐
Reddit
reddit.com › r/powershell › arraylist is adding a list of numbers before my data
r/PowerShell on Reddit: Arraylist is adding a list of numbers before my data
October 16, 2024 -

I am working with Cisco DNA Center (DNAC) to get a list of Network Devices and then pick out just the relevant data. I am able to get the full list of data from DNAC and I am testing creating a new arraylist with the 4 fields that I want from there. I am using $newlist = Testing -allnads $newinfo where $newinfo is the array of PSCustomObjects that I have gotten from DNAC.

Function Testing{
param($allnads) 
$paredlist = New-Object System.Collections.ArrayList 
foreach($device in $allnads){ 
$pareddown = @($device.hostname, $device.managementIpAddress, $device.id, $device.softwareversion) 
$paredlist.add($pareddown)
}
return $paredlist 
}

$newinfo.count is 923 but then $paredlist.count is 1846
The first 923 indexes are all just the index value.
$newlist[0] is 0, $newlist[1] is 1, etc
$newlist[923] gives me the hostname, IP, GUID, and software version of the first switch which I would have expected at index 0.

Is there something stupid I am doing here (probably the case) or some bit of wizardry I need to know about before I just start any iterations through this data with

$i = $newlist.count/2
if($i -lt $newlist.count){... $i +=1}
Top answer
1 of 2
4
I can't see your code, but If you are using ArrayList then the add() method will return the position of the new item. Best fix is to instead use the List type from the generics namespace. List does not return anything on add. ie: $List = [System.Collections.Generic.List[psobject]]::new() # $List.Add($object) # won't output anything. You can also strongly type the list by putting the type where i put psobject here.
2 of 2
3
As mentioned already you can use a generic list instead of an arraylist, but an even better option is to just assign the result of the foreach expression: Function Testing { param($allnads) $paredlist = foreach($device in $allnads) { @($device.hostname, $device.managementIpAddress, $device.id, $device.softwareversion) } return $paredlist } however returning a collection like this kinda goes against the PowerShell pipeline principles. Instead you should be writing the objects one by one to the pipeline so downstream commands can start processing the data immediately. For example if I only want the first X results then I could do Testing | Select-Object -First 10 and your function could stop after the first 10 items instead of having to process all the items just to end up throwing everything past the first 10 results away. This is how you would do that: Function Testing { param($allnads) foreach($device in $allnads) { @($device.hostname, $device.managementIpAddress, $device.id, $device.softwareversion) } } One last important detail here is that PowerShell will automatically unroll collections for you but since you are intentionally creating an array with @() and you presumably don't want it unwrapped by PowerShell you need to prefix it with a comma like this: ,@($device.hostname, $device.managementIpAddress, $device.id, $device.softwareversion).
🌐
Reddit
reddit.com › r/powershell › replace [system.collections.arraylist] with something thread-safe
r/PowerShell on Reddit: Replace [System.Collections.ArrayList] with something thread-safe
May 14, 2024 -

Hi.

I writing scripts that involve multiple API and due to the sequential nature of the single-threaded approach, some take a lot of time to execute.

For a long time I used ArrayList and "+=" approach to create list of arrays but it seems that it's deprecated and not really a best practice. See LINK1 and LINK2.

So, until now, I used approach from LINK1: declare empty ArrayList, looped through the results of my API call with foreach and then added entries with +=.

Of course, it doesn't work with Foreach-Object -Parallel, because ArrayList isn't thread safe.

I tried using ConcurrentBag but I can't access my items like I did in the past.

I.e., if I declare:

$devices = [System.Collections.Concurrent.ConcurrentBag[PSObject]]::new()

I'd like to be able to:

  • $devices[0] - select the first device from the list

  • $devices | Where-Object {$_.SerialNumber -eq "ABC1234567890"}

Doing any of these returns all the results.

Is there any other structure, similar to ArrayList or am I doing something wrong here?

🌐
Wit IT
witit.blog › array-vs-arraylist-powershell
Array vs ArrayList (PowerShell) - Wit IT - witit
December 22, 2022 - In conclusion, other than a few potential gotchas with data types, ArrayLists provide a noticeable improvement in processing time compared to Arrays. This can speed up your scripts somethin’ fierce if you’re working with large amounts of data.
🌐
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
🌐
Evotec
evotec.xyz › home › blog › powershell – few tricks about hashtables and arrays i wish i knew when i started
PowerShell – Few tricks about HashTables and Arrays I wish I knew when I started | Evotec Blog
February 18, 2019 - The warning above basically means you shouldn't use it in PowerShell unless you have to. They propose using GenericList instead. There's also a problem that they don't behave the same way Array does when it comes to adding two ArrayLists or GenericLists together.