Pipe it to Format-Table -AutoSize. (In the latest versions of PowerShell 5.0, PowerShell does this automatically for the first few objects in the pipeline.)
I am so absent minded sometimes. I forgot that I had used an out-string earlier in my code and saved the data to a variable using -outvariable so I can re-use that, as part of the final output later which is what the code I initial posted was. This must be why it cannot do what I want, because it is a string and not objects now.
Is there a way to save actual objects in a variable without piping to Out-String -OutVariable?
It’s a little unclear what you’re trying to accomplish. Are you trying to save the contents of an object to a file so it can be used later in another script or function? If that the case I would use ExportClixml.