I have a question. Why would using StringBuilder to append Get-Content produce a System.Object when $StringBuilder.ToString() is called. See below.
$stringBuilder = New-Object System.Text.StringBuilder $content = Get-Content -Path C:\temp\file.txt $stringBuilder.Append($content) $stringBuilder.ToString() # System.Object
If I force the $Content to be a string, $stringBuilder.ToString() will return the content of the file but all formatting is lost.
[string]$content = Get-Content -Path C:\temp\file.txtor
My question is why and how could I fix this? The code is used in a ForEach-Object loop to append files to a file in a particular order. I may be comming at this from a more c# point of view.
Thank in advance…