Heres my code, it works but I can't understand why you need $line inside the loop
foreach($line in $Array)
{
Add-Content "$HOME\filename.txt" $line
}
I want to understand but my teacher is not being very cooperative
Let's say that you had written the following:
foreach($line in $Array)
{
Add-Content "$HOME\filename.txt" "Hello, world"
}
What would be written out to the file? The answer is that the same string, "Hello, world" would have been written out, over and over again, until there weren't any more items in the array. Well, that's dumb. So, if you want the output on each line to reflect the aprt of the array that is current, you have to use $line as the parameter for what you are writing.