Inline arrays in PowerShell

imageSometimes I want to process a list of “things” easily in PowerShell where the list is not in an external file but in the script itself.

Ideally this list would not be separated by e.g. a comma so it can be easily copy/pasted from external data sources.

Something like this:

$List = @("
John Doe
Jane Doe
James Bond
And so the list goes on
")

With a little trickery we can!

cls

$List = @("
John Doe
Jane Doe
James Bond
And so the list goes on
") -split "`n" | where {[byte]$_[1] -ne 0x0}

foreach ($Entry in $List)
{
	"Performing surgery on $Entry"
}