Powershell Test if array in one line
arrays, powershell, split
Solution
Instead of doing:
$csv = (gc $FileIn)
you had to
$csv = @(gc $FileIn)
Now the output will always be an array of strings irrespective of the file having one line or not. The rest of the code will just have to treat `$csv` as an array of strings. This way is better than having to check if the output is an array etc., at the least in this situation.
Problem
I do a get-content on a file. Sometimes there are a lot of lines, but it can happen there is only one line (or even 0) I was doing something like ``` $csv = (gc $FileIn) $lastID = $csv[0].Split(' ')[1] #First Line,2nd column ``` But with only one line, gc return a string and $csv[0] return the first caracter of the string instead of the complete line, and the following Split fail. Is it possible to do something like : ``` $lastID = (is_array($csv)?$csv[0]:$csv).Split(' ')[1] ``` And to do that only if $csv contains at least a line? Thx for your help, Tim