Looks like you don't want an actual list, but a string with a listing of variables. A multiline string with the names and values of your variables could be defined like this:

Copy$list = @"
a: ${a}
b: ${b}
c: ${c}
"@

Another, more dynamic, option would be something like this:

Copy$list = 'a', 'b', 'c' | ForEach-Object {
    "${_}: $(Get-Variable $_ -ValueOnly)"
} | Out-String

where you specify a list with the variable names, output strings containing each variable name and the corresponding value, and merge those into a single string at the end.

Answer from Ansgar Wiechers on Stack Overflow
๐ŸŒ
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
March 24, 2025 - Because arrays are such a basic feature of PowerShell, there is a simple syntax for working with them in PowerShell. ... We can create an array and seed it with values just by placing them in the @() parentheses. PS> $data = @('Zero','One','Two','Three') PS> $data.Count 4 PS> $data Zero One Two Three ยท This array has 4 items. When we call the $data variable, we see the list of our items.
๐ŸŒ
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 - I never remember how to write the generic list type, and how do I use it for any type (using psojbect type?) ?. ... Yeah, I've done the same thing, especially when writing ad hoc blocks of code. However, if you're using Powershell v7, you can type [List and hit Ctrl+Space at the command line and it'll populate it for you.
๐ŸŒ
O'Reilly
oreilly.com โ€บ library โ€บ view โ€บ windows-powershell-cookbook โ€บ 9781449359195 โ€บ ch07.html
7. Lists, Arrays, and Hashtables - Windows PowerShell Cookbook, 3rd Edition [Book]
January 10, 2013 - PowerShell makes working with arrays and lists much like working with other data types: you can easily create an array or list and then add or remove elements from it. You can just as easily sort it, search it, or combine it with another array.
Author ย  Lee Holmes
Published ย  2013
Pages ย  1034
๐ŸŒ
Microsoft
devblogs.microsoft.com โ€บ dev blogs โ€บ scripting blog [archived] โ€บ list files in folders and subfolders with powershell
List Files in Folders and Subfolders with PowerShell - Scripting Blog [archived]
February 3, 2014 - This command lists all files and folders that are at the E:\music level. This command does not recurse through the entire structure. The command and a sample output are shown in the following image: If I want to only see the folders at this level, I use the โ€“Directory switch. Note The โ€“Directory, -File, -Attributes, -Hidden, and โ€“System switches were added to Get-ChildItem cmdlet in Windows PowerShell 3.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.
Find elsewhere
๐ŸŒ
pnpm
pnpm.io โ€บ installation
Installation | pnpm
4 days ago - On Windows, Microsoft Defender can significantly slow down installation of packages. You can add pnpm to Microsoft Defender's list of excluded folders in a PowerShell window with administrator rights by executing:
๐ŸŒ
ThisCodeWorks
thiscodeworks.com โ€บ 686dc6d77720ce0014b76467
Create a table, or an array of lists in PowerShell
Save code snippets in the cloud & organize them into collections. Using our Chrome & VS Code extensions you can save code snippets online with just one-click!
๐ŸŒ
Starship
starship.rs โ€บ config
Starship: Cross-Shell Prompt
3 weeks ago - # ~/.config/starship.toml [shell] fish_indicator = '๓ฐˆบ ' powershell_indicator = '๏‘ _' unknown_indicator = 'mystery shell' style = 'cyan bold' disabled = false
๐ŸŒ
TechTarget
techtarget.com โ€บ searchwindowsserver โ€บ tip โ€บ Top-PowerShell-commands-you-must-know-with-cheat-sheet
Top PowerShell commands you must know, with cheat sheet | TechTarget
They are available in both Windows PowerShell 5.1 and PowerShell 7. Any differences between versions are highlighted. The Get-Command cmdlet performs command discovery. Using various parameters, Get-Command can list all commands currently available, commands for a specific module or even commands matching a filter.
๐ŸŒ
Spiceworks
community.spiceworks.com โ€บ programming & development
Powershell Array list - Programming & Development - Spiceworks Community
April 27, 2020 - Hi Team, 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 Get-ADComputer -Server [First Array] -searchbase [Second array] -filter * -Properties LastLogonDate,Name,Description,Created| Where-Object {$_.LastLogonDate -lt $date.AddDays(-60)}| Select-Object Name,DistinguishedName,Created,LastLogonDa...
๐ŸŒ
Vexx32
vexx32.github.io โ€บ 2020 โ€บ 02 โ€บ 15 โ€บ Building-Arrays-Collections
Building Arrays and Collections in PowerShell
While the .NET documentation frequently uses the C# syntax List<T>, when we get to PowerShell we actually use square brackets to indicate the generic type parameter instead. List<T> instead becomes [List[T]], and in practical usage T is replaced with another type name.
๐ŸŒ
Let's Encrypt
letsencrypt.org โ€บ docs โ€บ client-options
ACME Client Implementations - Let's Encrypt
Posh-ACME (PowerShell) ACME-PS (PowerShell) kelunik/acme-client (PHP) Certify The Web (Windows) WinCertes Windows client ยท GetCert2 (simple GUI - .Net, C#, WPF, WCF) TekCERT (GUI, CLI) simple-acme Spiritual successor to win-acme, also works on Linux! Certera (Crossplatform PKI to centrally manage keys and certificates) CertKit Deployable and SaaS certificate lifecycle management and monitoring ยท
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ answers โ€บ questions โ€บ 327557 โ€บ list(t)-in-powershell
List<T> in PowerShell? - Microsoft Q&A
March 23, 2021 - [System.Collections.Generic.List[Errors]] $errors = @() # Or $errors = New-Object System.Collections.Generic.List[Errors]
๐ŸŒ
Varonis
varonis.com โ€บ blog โ€บ powershell-array
PowerShell Array Guide: How to Use and Create
June 9, 2022 - Which will list the items we put in the array. Now we have an array, we will want to access items from it. There are several ways to do this. The first is to use the index of the items in the array. As we said before, indexes start at 0, so to retrieve the first item in our array we will need to tell PowerShell ...
๐ŸŒ
ScriptRunner
scriptrunner.com โ€บ blog-admin-architect โ€บ powershell-array-types
Typed PowerShell Arrays and Generic Lists
May 22, 2025 - PS> $list = [System.Collections.Generic.List[string]]::new() PS> $list.IsFixedSize False ยท The example above can now be rewritten to avoid using +=. Keep in mind that this example is meant to illustrate the issue; with just 10 iterations, as shown here, you could likely get away with using +=. However, remember the examples from the previous section where += would hang Windows PowerShell.
Top answer
1 of 2
12

The direct equivalent of that command in PowerShell would be dir -n > dirlist.txt.

The long (canonical) form of the command is Get-ChildItem -Name > dirlist.txt.

If you want to include subdirectories, that's dir -n -r > dirlist.txt and Get-ChildItem -Name -Recurse > dirlist.txt respectively.


dir in PowerShell is simply another name for Get-ChildItem, but unfortunately has different option names (-n vs /b) compared to cmd's dir command of the same name.

2 of 2
0

Do you see that menu option, "Open Power_S_hell window here"? Well, you can select that, and get one of those blue-windowed PowerShell windows.

Then, instead of running:

dir /b optional-target > output.txt

You can run this:

cmd
dir /b optional-target > output.txt
exit

Yes, the process is longer. That's the downside. The upsides are that it's an easy workaround, and this process lets you do the same things, in the same way, that you did with the traditional DOS-like command prompt. (Also, having PowreShell run CMD is a technique that ought to work on basically any Windows 10 computer, not just the ones where you've taken the time to re-add a desirable menu option to a context menu.)

When you run "cmd", you'll notice the command prompt will stop saying "PS " at the start of your prompt. That is how you can tell that the computer is ready to accept the traditional-style syntax. Since your command prompt will technically be using CMD, you won't have Powershell trying to insist on you using new parameters/options, and you won't need to worry about PowerShell doing screwy stuff with unescaped commas and quotation marks (until you run the first exit command, which leaves CMD and goes back to PowerShell).

๐ŸŒ
Scoop
scoop.sh
Scoop
A command-line installer for Windows
๐ŸŒ
Kamil Procyszyn
kamilpro.com โ€บ posts โ€บ powershell array and arraylist - storing multiple items as a one variable
PowerShell Array and ArrayList - storing multiple items as a one variable | Kamil Procyszyn
August 23, 2021 - # PowerShell however allows you to do that, hiding all complexity # by creating a new array, copying all existing item, adding new one # and finally removing old array. # If you plan to add items to your array, look at ArrayList and List below # Adding elements to array $Week $Week.Add("January") #this throws an error $Week += "January" $Week # Adding arrays together $ArrayA = 1..10 $ArrayB = 11..20 $ArrayA + $ArrayB ############# # ArrayList # ############# #Adding items to ArrayList $alist = [System.Collections.ArrayList]::new() #This is .Net framework $alist.Add("January") [void]$alist.Add("February") #Void stops prevents writing to console $alist # Removing from ArrayList $alist.Remove($alist[1]) $alist