You're not evaluating the array. By writing "$Names[0]"
it is the equivalent of $Names + "[0]"
.
You need to nest the evaluation inside $(...)
.
Try this:
$Machinename | ForEach-Object {Write-Output "$($Names[0])"}
That gives me:
john
john
Equally, as pointed out in the comments, this works too:
$Machinename | ForEach-Object {Write-Output $Names[0]}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…