Out-File presents information basically exactly as it would show up at the console (including using the same console width, if I remember correctly.) If you want to allow really long lines in the file, you can pass a large value to Out-File’s -Width parameter. Or, alternatively, you could use something like a CSV file instead. The difference there would be whether you intend for a script or program to read this data later, or if it’s meant to be more readable for people instead. Format-Table produces a human-readable format, but one that would be very annoying to have to read in with a script. CSV is intended for programs and scripts to parse, and can be opened directly with programs like Microsoft Excel.
Dave,
Thank you for the wealth of information. You are correct I will want to read the data back in after.
So If I am understanding this correctly I should be changing this line to something else to import the information back in later.
Yep. Instead of Format-Table, you would use Select-Object, and then pipe the results to Export-Csv instead of Out-File. That would allow you to use Import-Csv on the file later (or to open it with Excel.)
In this example, I’ve split the command into multiple lines to make it a bit easier to read: