How do I save the PowerShell script output to a text file in tab-delimited format?
Example - How do I export the output of the below PowerShell script to text, tab-delimited format?
Get-MailboxStatistics -Database data01 |ft displayname,databasename,itemcount,totalitemsize
As of now, there is no built-in command like CSV (Export-CSV) to export output to the excel file but we can use the Out-File command to export data to excel or any other file format. Let's use Out-File to export the output of the Get-Processes command to an excel file.
To do this we can use the Export-CSV function in PowerShell. The Export-CSV function converts PowerShell objects into a CSV string and saves them into a CSV file. If you only need a CSV string, then you can also use the ConvertTo-CSV function in PowerShell.
There are a couple of ways to write the output of PowerShell to a file. The most common ways are to use the Out-File cmdlet or the redirection operator > . Other options are to use the Set-Content and Add-Content cmdlet.
Use the Export-CSV
with a tab delimiter. Note, that you can't use the output of format-table
as an input to export-CSV
, use select-object
instead:
Get-MailboxStatistics -Database data01 | select displayname,databasename,itemcount,totalitemsize | export-csv -delimiter "`t" -path theOutFile.txt -notype
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With