Borbin the 🐱

Using List in PowerShell

24 April, 2022


PowerShell has lots of array and lists support, but changing or creating a list with dynamic data recreate the list on each change which is inefficient for large lists.
The most simple solution is to use the .NET List class:

    [System.Collections.Generic.List[string]]$content = [System.Collections.Generic.List[string]]::new()

    $content.Add("line1")
    $content.Add("line2")