Creating String Arrays without Quotes

by May 14, 2013

Often, you may need a list of strings and want to store it in a variable. The common coding practice is like this:

$MachineType = 'Native','I386','Itanium','x64'

A much easier approach does not require quotes or commas. It simply submits the strings you want in your list as parameters to Write-Output. Write-Output is a cmdlet, so it does not require quotes around strings (unless they contain special characters or spaces):

$MachineType = Write-Output Native I386 Itanium x64

The result is the same in both cases.

Twitter This Tip! ReTweet this Tip!