Home/PowerShell/How to get the array as input using Powershell

How to get the array as input using Powershell

To read an array into Read-Host, you would need to put it in a loop because anything entered into Read-Host will be interpreted as a string. To make output in new line we can use $OFS, which is a special variable in powershell . OFS stands for Output field separator . You would use this to separate object/Array.

The .split() method is self explanatory, the .trim() method will simply remove leading and trailing spaces and leading and trailing line breaks

Example #1 : Getting Value as an Array by Looping

OUTPUT:

Example 2# : Alternative approach for handling the multiple inputs without loop.

Output:

Leave a Reply