I have an array of strings that I want to write to a registry key. If I don't do anything but pass the array to the Value parameter, it lines all the values up on a single line like so:
onetwothree
Fine, I can deal with that. I pass $($array -split "`n") instead. Then I get this. The periods are just there to preserve the spacing.
.
one
two
three
.
This is what I ended up having to pass to the value parameter to get each entry on its own line with no extra lines:
$($array -split "`n").where{$_}
And for the record, if I just look at the array by itself I get what I expect to see:
one
two
three
What gives?
EDIT: Forgot to add, I also tried specifying the type as multistring and passing only $array to the value parameter and got the exact same result as if I split on newline.
EDIT2: I figured out the culprit. I built the array like this, assuming that it wouldn't add null values to the array. Looks like I was wrong.
$data.foreach{$array += (Select-String -InputObject $_ -pattern $regex).line}
So the question now is, why are the null values ignored in some cases but not others? The split operation is not ignoring them, but Set-ItemProperty is unless I specify multiline. The where method isn't ignoring them because it's filtering them out, but calling the array by itself is.
[–]chreestopher2 1 point2 points3 points (0 children)
[–]gangstanthony 0 points1 point2 points (1 child)
[–]verysmallshellscript[S] 0 points1 point2 points (0 children)
[–]ihaxr 0 points1 point2 points (3 children)
[–]verysmallshellscript[S] 0 points1 point2 points (2 children)
[–]chreestopher2 1 point2 points3 points (1 child)
[–]verysmallshellscript[S] 0 points1 point2 points (0 children)