Note the following output. $Names is an array with two values. $Machinename is an array with two values.
Their positional values within the array are retrieved accurately outside of a foreach loop. When fetched within a foreach loop the value requested for the first position in the array i.e. $Names[0] ignores the positional call of [0]..... I need to be able to retrieve that value by itself..... Ultimately I will need to interate through each value to input to a command...
PS C:\Users\lab> $Names
john
jeff
PS C:\Users\lab> $Names[0]
john
PS C:\Users\lab> $Names[1]
jeff
PS C:\Users\lab> $Machinename
dev1
dev2
PS C:\Users\htlab> $Machinename | ForEach-Object { Write-Output "$Names[0]"}
john jeff[0]
john jeff[0]
Sample Script:
$Names = 'john', 'jeff'
$machinename = 'dev1', 'dev2'
$Machinename | ForEach-Object {Write-Output "$Names[0]"}