PowerTip: Create Array in PowerShell

Doctor Scripto

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(',')

0 comments

Discussion is closed.

Feedback usabilla icon