Formatting question RRS feed

  • Question

  • Good afternoon,

    I have the following script in exchange power-shell that returns a csv file with the information requested

    It returns the information I require but I need assistance with formatting.

    (Please view screenshot of results below code) the script returns size values in GB, MB and KB

    #Get the info from the server and sort it by size
    Get-MailboxStatistics -Server exXXXXXXXX | Sort-Object TotalItemSize -Descending | Select DisplayName, TotalItemSize, TotalDeletedItemSize | Export-CSV C:\sizemailbox\mbs.csv
    # Set the current date
    $datetable = (get-date -Format s).Replace("-","").Replace(":","").Replace("T","")
    Write-Host "Report generation in date of "+"$datetable"
    # File variables
    $location = "c:\sizemailbox\"
    $BASE = "mbs.csv"
    $filename = $location+"$datetable"+"-"+"MailboxSizeReport_PerUser.csv"
    $oldfile = $Location+$BASE
    # Rename file for current date
    rename-item $oldfile $filename
    Write-Host "Report Generated" -ForegroundColor DarkGreen

    Information that is returned:

    This is what I am looking for and why I am requesting assistance:

    1- remove the size magnitude (GB, MB, KB)

    2- remove the parenthesis and its content on size columns

    3- convert the sizes to MB with 3 decimals.

    Please view example that I edited by hand

    Thank you kindly,


    Wednesday, April 25, 2018 7:03 PM

All replies

  • Have a look at this example: Export Mailbox Size to CSV using Powershell Script

    It basically show what you need to do is add a calculated property to convert the TotalItemSize and TotalDeletedItemSize to MB (or KB divided by 1024 to get the decimal places):

    @{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToKB()/1024}}
    Also, use
    Export-Csv -NoTypeInformation to get rid of the first #TYPE line in your file.

    • Edited by F. Van Roie Wednesday, April 25, 2018 10:00 PM
    Wednesday, April 25, 2018 9:58 PM
  • Good afternoon Mr. Van Roie,

    Thank you kindly for your assistance. It is working perfectly!

    Have a great day and thank you again.


    Wednesday, May 2, 2018 6:25 PM
  • Hi Alexandre,

    Can you please upvote the reply and mark the thread as answered?


    Thursday, May 17, 2018 3:37 PM