Conside this: This is one array and contains only one item. And the item of the array is another array(I call it list object). I want to get the only list object inside an array.
I use foreach to get the list, but it treates the list object as an array and return the first item of the list object.
$OSName1 = @(
@("win2008r2")
)
$OSName2 = @(
@("win2008r2"),
@("win2012")
)
foreach ($osname in $OSName1) {
write-host $osname[0]
}
foreach ($osname in $OSName2) {
write-host $osname[0]
}
I expect the output of result is: win2008r2 win2008r2 win2012
But the real result is w win2008r2 win2012 Why powershell auto expands the inside array to it parent?
See Question&Answers more detail:os