I would like to retrieve the contents of a file, filter and modify them and write the result back to a file. I do this:
PS C:\code> "test1" >> test.txt
PS C:\code> "test2" >> test.txt
PS C:\code> $testContents = Get-Content test.txt
PS C:\code> $newTestContents = $testContents | Select-Object {"abc -" + $_}
PS C:\code> $newTestContents >> output.txt
output.txt contains
"abc -" + $_
------------
abc -test1
abc -test2
What gives with that first line? It's almost like foreach gives back an IEnumerable - but $newTestContents.GetType() reveals it is an object array. So what gives? How can I get the array to output normally without the strange header.
Also bonus points if you can tell me why $newTestContents[0].ToString() is a blank string