Link to home
Start Free TrialLog in
Avatar of bruce_77
bruce_77

asked on

Exporting Powershell to formatted CSV file

Hello

Running Powershell v2. I have the following command that pulls mailbox name and sizes for a list of users.

But when it exports to CSV, the data is not formatted properly. What I'd like to do is have Display Name and Mailbox Size in seperate columns on the CSV file but this doesn't seem possible? When the data is exported it all appears in the same column?

Get-content c:\LIST.txt | Get-mailbox | Foreach-object {get-mailboxstatistics -identity $_} | fl displayname, @{ expression={$_.TotalItemSize.Value.ToMB()}} > c:\export.csv

SOLUTION
Avatar of Hendrik Wiese
Hendrik Wiese
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Qlemo
Don't use any formatting cmdlet (format-*) if you export into CSV. Just use export-csv - it is exactly for that purpose:
Get-content c:\LIST.txt | Get-mailbox | Foreach-object {get-mailboxstatistics -identity $_}  | select displayname, @{n="Size (MB)"; e={$_.TotalItemSize.Value.ToMB()}} | export-csv c:\export.csv

Open in new window

Avatar of bruce_77
bruce_77

ASKER

Thanks...

So what is the difference between using "| fl displayname" and "| select displayname"?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial