How do you convert an arbitrary text file to an Excel spreadsheet?
Getting the content of a file is easy.
$text = Get-Content "myfile.txt"
But text isn't a spreadsheet so you'd then have to do some sort of script-specific logic to convert it into a spreadsheet that would make sense. Perhaps you could convert to CSV using PS if that made sense for your data.
$csv = ConvertTo-Csv -InputObject $text
Or export directly to a csv file.
Export-Csv -InputObject $text -Path "myfile.csv"
Excel understands CSV files so this file could be opened in Excel. If you want an actual Excel file then you'll need to convert it to OpenXML format with PS doesn't support out of the box. If Excel is installed on the machine then you can use the Excel COM API to create the file. Rather than posting all that code here, refer to this blog article that talks about converting a text file to an Excel file.