March 31st, 2015

PowerTip: Create Array in PowerShell

Doctor Scripto
Scripter

Summary: Use Windows PowerShell to easily create an array.

Hey, Scripting Guy! Question Can I use Windows PowerShell to create an array of strings and avoid typing quotation marks
           around all the strings?

Hey, Scripting Guy! Answer Instead of creating an array, such as this: $array = “a”,”b”,”c”,”d”,”e”,”f”,”g”,”h”, use a single string,
           and split it at the comma. It will be much less typing, and a whole lot faster. Here is an example:

$array = 'a,b,c,d,e,f,g,h'.Split(',')

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.