A PowerShell array is fixed in size after creation, while an ArrayList is mutable and supports easier insertion, removal, and clearing of elements. Arrays are useful for predictable collections and typed data, but ArrayLists are better when scripts must change the collection repeatedly during execution. Choose based on how often the data changes.
When to use a fixed array versus a resizable list
The practical difference is capacity and mutability. A PowerShell array is created with a fixed length, so expanding it means creating a new array and copying values. An ArrayList is designed for repeated growth and shrink operations, so it is the better fit when items are added, removed, or reordered during a script run.
That difference matters most when the collection changes often. If you are building a known set of values once and then iterating over it, an array is simpler and usually the cleaner choice. If you are accumulating results from loops, filters, or discovery steps, the ArrayList model is more efficient to work with interactively.
What changes in day-to-day PowerShell scripting
Arrays are a better match for stable, predictable data. They work well when you already know the number of items, or when the collection will be treated as read-only after creation. Their fixed size is not a flaw so much as a design tradeoff: you get a simple data structure, but not easy in-place resizing.
ArrayLists fit scripts that behave more like a staging area. You can append, remove, or clear items without rebuilding the whole collection each time. In practice, that makes them useful for building lists from event output, inventory data, or conditional logic where the final set is not known at the start.
One practical nuance is that PowerShell has evolved, and many scripts now use more modern collection patterns for performance and clarity. Even so, understanding the array versus ArrayList distinction still helps when reading older scripts, troubleshooting mutation behavior, or deciding whether a collection should be treated as fixed or dynamic.
How to choose the right collection for the job
Choose an array when the script values simplicity, stable ordering, and predictable data shape. Choose an ArrayList when the script needs repeated insertions, deletions, or incremental construction inside a loop. If the collection only changes once, the array’s fixed nature is rarely a problem. If it changes many times, the ArrayList avoids awkward rebuild patterns.
What to verify: Check whether the script mutates the collection after creation. If it does, a fixed array can force extra copying or more complicated code, while an ArrayList can keep the logic straightforward.
Common mistake: Treating every collection as interchangeable. In PowerShell, that usually leads to code that works but becomes harder to maintain, especially when later edits introduce item removal or repeated appends.
Practitioner takeaway: The decision is less about syntax and more about lifecycle, use arrays for stable sets of data and ArrayLists for collections that must evolve while the script is running.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
NIST CSF 2.0, NIST SP 800-53 Rev 5 and CIS Controls v8 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| NIST CSF 2.0 | ID.AM-01 — Physical devices and systems are inventoried | Collection choice affects how script-managed inventories are built and maintained. |
| Recommendation — Use stable data structures for fixed inventories and dynamic lists for incremental discovery. | ||
| NIST SP 800-53 Rev 5 | CM-8 — System Component Inventory | Collection handling is relevant to maintaining accurate component inventories and updates. |
| Recommendation — Use a mutable collection when inventory records must be added or removed during processing. | ||
| CIS Controls v8 | CIS-1 — Inventory and Control of Enterprise Assets | Scripts often build and update asset collections, where resize behavior affects maintainability. |
| Recommendation — Choose the collection type that best supports repeated inventory updates and reconciliation. | ||
Related resources from NHI Mgmt Group
- What is the difference between direct access and effective access in Active Directory?
- What is the difference between managing human identities and non-human identities?
- What is the difference between IaaS and PaaS for application teams?
- What is the difference between IAM database records and IAM configuration in a deployment pipeline?
Deepen Your Knowledge
Reviewed and updated by the NHIMG editorial team on September 25, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org