none
Exchange powershell script to find all users mailbox sizes

    Question

  • Hi guys, I'm using the following script to tell me how big everyone's mailboxes are.

    Get-MailboxStatistics -Server 'SERVERNAME' | where {$_.ObjectClass -eq “Mailbox”} | Sort-Object TotalItemSize -Descending | ft @{label=”User”;expression={$_.DisplayName}},@{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}}  -auto >> “c:\Temp\mailbox_size.txt”

    Pretty straight forward, exports as a text file.

    I want to archive the files for future reference., so how can I have the text file created with the date & time it was created in the file name?

    thanks in advance :)

    Shane

    Monday, March 5, 2012 12:58 AM

Answers

  • What I would do is (and put all of these lines in a notepad to save to a .ps1 file) is to start with your line above and combine it with code to rename the file you created.  Here is the script in its entirety: [a bit of rough powershell code here]

    Get-MailboxStatistics -Server 'SERVERNAME' | where {$_.ObjectClass -eq “Mailbox”} | Sort-Object TotalItemSize -Descending | ft @{label=”User”;expression={$_.DisplayName}},@{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}}  -auto >> “c:\Temp\mailbox_size.txt”

    # Set the current date

    $a = get-date
    $month= $a.month
    $day= $a.day
    $year= $a.year

    # File variables

    $location = "c:\temp"
    $BASE = "mailbox_size.txt"
    $filename = $location+"$month"+"-"+"$day"+"-"+"$year"+"-"+$BASE
    $oldfile = $Location+$BASE

    # Rename file for current date

    rename-item $oldfile $filename


    JAUCG

    Monday, March 5, 2012 3:53 AM

All replies

  • What I would do is (and put all of these lines in a notepad to save to a .ps1 file) is to start with your line above and combine it with code to rename the file you created.  Here is the script in its entirety: [a bit of rough powershell code here]

    Get-MailboxStatistics -Server 'SERVERNAME' | where {$_.ObjectClass -eq “Mailbox”} | Sort-Object TotalItemSize -Descending | ft @{label=”User”;expression={$_.DisplayName}},@{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}}  -auto >> “c:\Temp\mailbox_size.txt”

    # Set the current date

    $a = get-date
    $month= $a.month
    $day= $a.day
    $year= $a.year

    # File variables

    $location = "c:\temp"
    $BASE = "mailbox_size.txt"
    $filename = $location+"$month"+"-"+"$day"+"-"+"$year"+"-"+$BASE
    $oldfile = $Location+$BASE

    # Rename file for current date

    rename-item $oldfile $filename


    JAUCG

    Monday, March 5, 2012 3:53 AM
  • Find Mail Box Size using Powershell

    http://pdtechguru.wordpress.com/2012/09/28/find-mail-box-size-using-powershell/
    Tuesday, October 16, 2012 3:23 AM
  • Hi guys, I'm using the following script to tell me how big everyone's mailboxes are.

    Get-MailboxStatistics -Server 'SERVERNAME' | where {$_.ObjectClass -eq “Mailbox”} | Sort-Object TotalItemSize -Descending | ft @{label=”User”;expression={$_.DisplayName}},@{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}}  -auto >> “c:\Temp\mailbox_size.txt”

    Pretty straight forward, exports as a text file.

    I want to archive the files for future reference., so how can I have the text file created with the date & time it was created in the file name?

    thanks in advance :)

    Shane

    Problem is, Get-MailboxStatistics output just a display name - not unique and cant really be used as such. The other half of the information you need is in Get-Mailbox :- found answer in following link. once you have the data on all your mailboxes, and the output can be IMPORTED into excel you can do all your sorting etc and delete whatever you dont want

    ***if this is what you were looking for, please click this link and give the guy some credit.. i didnt come up with this, i just found it


    #REM http://www.experts-exchange.com/Software/Server_Software/Email_Servers/Exchange/Q_27828458.html

    $Mailboxes = Get-Mailbox -ResultSize Unlimited
    foreach ($Mailbox in $Mailboxes)
    {
     $Mailbox | Add-Member -MemberType "NoteProperty" -Name "MailboxSizeMB" -Value ((Get-MailboxStatistics $Mailbox).TotalItemSize.Value.ToMb())
    }
    $Mailboxes | Sort-Object MailboxSizeMB -Desc | Select PrimarySMTPAddress, MailboxSizeMB


    #REM - to export this out -- do the following ;) enjoy (see the part where it says "Select" you can add additional fields like ALIAS etc to this)

    $Mailboxes = Get-Mailbox -ResultSize Unlimited
    foreach ($Mailbox in $Mailboxes)
    {
     $Mailbox | Add-Member -MemberType "NoteProperty" -Name "MailboxSizeMB" -Value ((Get-MailboxStatistics $Mailbox).TotalItemSize.Value.ToMb())
    }
    $Mailboxes | Sort-Object MailboxSizeMB -Desc | Select PrimarySMTPAddress, MailboxSizeMB | Export-Csv -NoType "C:\temp\Mailboxessize.csv"

     


    Wednesday, July 30, 2014 12:09 PM
  • I use this.

    Get-MailboxDatabase | Get-MailboxStatistics | Sort totalitemsize -desc | ft displayname, totalitemsize, itemcount | Out-File "path\file name"

    Thursday, November 26, 2015 12:56 PM
  • No you don't - it's not a valid command.
    Friday, May 12, 2017 3:13 PM
  • DeepFriedMice - why are you responding to a two year old response on a question that was answered 5 years ago? Also, did you attempt the command suggested above before suggesting its not valid? I just tested it in a lab and it works fine. I was able to dump out a list of all mailboxes in the environment with the three selected values. Now you can also run this:

    Get-ExchangeServer|Get-MailboxStatistics|Sorttotalitemsize-desc|ftdisplayname,totalitemsize,itemcount|Out-File"c:\downloads\sizes.csv"

    OR

    Get-Mailbox|Get-MailboxStatistics|Sorttotalitemsize-desc|ftdisplayname,totalitemsize,itemcount|Out-File"c:\downloads\sizes.csv"

    Now, the only real difference between the suggested one and the other two I have above is that the Get-Mailbox one only shows user mailboxes, whereas Get-MailboxDatabase and Get-ExchangeServer also retried HealthMailboxes Archives and more. 

    In the end, test before making a comment on something you did not verify.


    Damian Scoles (MVP) - Please remember to mark replies as helpful if they were or as answered if I provided a solution.


    Friday, May 12, 2017 3:31 PM