Hi
I’m testing 3 different foreach loops with arrays. My First loop is popullating the correct oputput.
$add_server = @(‘Server one’, ‘Server two’, ‘Server three’)
foreach ($i in $add_server) {
Add-Content -Path “C:\Users\spate\Documents\SampleFile3.txt” -Value “$i”
}
Output
Server one
Server two
Server three
- Not correct output
$add_server | ForEach-Object (Add-Content -Path “C:\Users\spate\Documents\SampleFile2.txt” -Value “$i”)
Output
Server three
3)Not correct
$add_server2.ForEach({
Add-Content -Path “C:\Users\spate\Documents\SampleFile5.txt” -Value “$i”
})
output
Server three
Server three
Servver three
For the incorrect output’s I think I have to initalize the array to index[0]
But not sure what the issues is.
Thanks