Rebecca asks:

I am trying to find a command that will return the user and total item count for the inbox only. Can this be done?

The solution to Rebecca’s scenario is in the Get-MailboxFolderStatistics cmdlet. This cmdlet can be used to report on some or all of the individual folders within a mailbox, returning such information as their size and item count.

For example:

Get-MailboxFolderStatistics alan.reid

If you ran that command against a mailbox in your organization you will see a lot of information returned. You may wish to return just a few of the more interesting bits of information instead, for example:

[PS] C:\>Get-MailboxFolderStatistics alan.reid | Select Name,FolderSize,ItemsinFolder

Name                         FolderSize               ItemsInFolder
----                         ----------               -------------
Top of Information Store     0 B (0 bytes)                        0
Calendar                     49.89 KB (51,083 bytes)             11
Contacts                     26.75 KB (27,388 bytes)              7
Conversation Action Settings 0 B (0 bytes)                        0
Deleted Items                0 B (0 bytes)                        0
Drafts                       0 B (0 bytes)                        0
Import1                      0 B (0 bytes)                        0
Calendar                     0 B (0 bytes)                        0
Contacts                     0 B (0 bytes)                        0
Conversation Action Settings 0 B (0 bytes)                        0
Deleted Items                0 B (0 bytes)                        0
Drafts                       0 B (0 bytes)                        0
Inbox                        6.489 KB (6,645 bytes)               1
Journal                      0 B (0 bytes)                        0
Junk E-Mail                  0 B (0 bytes)                        0
Notes                        0 B (0 bytes)                        0
Outbox                       0 B (0 bytes)                        0
Recoverable Items            0 B (0 bytes)                        0
Deletions                    0 B (0 bytes)                        0
Purges                       0 B (0 bytes)                        0
Versions                     0 B (0 bytes)                        0
Sent Items                   0 B (0 bytes)                        0
Tasks                        0 B (0 bytes)                        0
Inbox                        347 KB (355,298 bytes)             167
Old mail                     0 B (0 bytes)                        0
Journal                      0 B (0 bytes)                        0
Junk E-mail                  389.4 KB (398,709 bytes)            10
News Feed                    0 B (0 bytes)                        0
Notes                        0 B (0 bytes)                        0
Outbox                       0 B (0 bytes)                        0
Quick Step Settings          0 B (0 bytes)                        0
RSS Feeds                    0 B (0 bytes)                        0
Sent Items                   351.2 KB (359,661 bytes)           157
Suggested Contacts           0 B (0 bytes)                        0
Sync Issues                  0 B (0 bytes)                        0
Conflicts                    0 B (0 bytes)                        0
Local Failures               0 B (0 bytes)                        0
Server Failures              0 B (0 bytes)                        0
Tasks                        0 B (0 bytes)                        0
Recoverable Items            127.5 KB (130,553 bytes)            54
Deletions                    0 B (0 bytes)                        0
Purges                       0 B (0 bytes)                        0
Versions                     0 B (0 bytes)                        0

Similarly you may wish to only look at specific folders and subfolders, which you can achieve using the -FolderScope parameter. For example:

[PS] C:\>Get-MailboxFolderStatistics alan.reid -FolderScope Inbox | Select Name,FolderSize,ItemsinFolder

Name     FolderSize               ItemsInFolder
----     ----------               -------------
Inbox    320.8 KB (328,501 bytes)           156
Old mail 25.42 KB (26,027 bytes)             11

So getting back to Rebecca’s question, what if we just want to know the total size of the inbox? The command above returns two values, one for the inbox and one for the subfolder “Old mail”. In a report of “Inbox sizes” we would want the total of both.

Fortunately one of the values returned by Get-MailboxFolderStatistics is for the size of the folder and subfolders.

[PS] C:\>Get-MailboxFolderStatistics alan.reid -FolderScope Inbox | Select Name,FolderandSubFolderSize,ItemsinFolderandSubfolders

Name     FolderAndSubfolderSize   ItemsInFolderAndSubfolders
----     ----------------------   --------------------------
Inbox    346.2 KB (354,528 bytes)                        167
Old mail 25.42 KB (26,027 bytes)                          11

Also, we just want the inbox itself in our report, not every subfolder listed individually.

[PS] C:\>Get-MailboxFolderStatistics alan.reid -FolderScope Inbox | Where {$_.FolderPath -eq "/Inbox"} | Select Name,FolderandSubFolderSize,ItemsinFolderandSubfolders

Name  FolderAndSubfolderSize   ItemsInFolderAndSubfolders
----  ----------------------   --------------------------
Inbox 346.2 KB (354,528 bytes)                        167

Finally, if I was interested in a report of the inbox sizes for all mailboxes in the organizations, I would probably whip up a quick script like this.

$mailboxes = @(Get-Mailbox -ResultSize Unlimited)
$report = @()

foreach ($mailbox in $mailboxes)
{
    $inboxstats = Get-MailboxFolderStatistics $mailbox -FolderScope Inbox | Where {$_.FolderPath -eq "/Inbox"}

    $mbObj = New-Object PSObject
    $mbObj | Add-Member -MemberType NoteProperty -Name "Display Name" -Value $mailbox.DisplayName
    $mbObj | Add-Member -MemberType NoteProperty -Name "Inbox Size (Mb)" -Value $inboxstats.FolderandSubFolderSize.ToMB()
    $mbObj | Add-Member -MemberType NoteProperty -Name "Inbox Items" -Value $inboxstats.ItemsinFolderandSubfolders
    $report += $mbObj
}

$report

Saving that as Get-InboxReport.ps1 I can then run it in the Exchange Management Shell.

[PS] C:\Scripts\>.\Get-InboxSize.ps1

I could even output it to CSV file for further analysis.

[PS] C:\Scripts\>.\Get-InboxSize.ps1 | Export-CSV inboxsizes.csv

exchange-powershell-inbox-size-report

The script above is just a few lines with no error handling, parameters, or other useful elements that you might find in a script, but it is just to give you an idea of what is possible with Get-MailboxFolderStatistics.

I hope that answers your question Rebecca.

About the Author

Paul Cunningham

Paul is a former Microsoft MVP for Office Apps and Services. He works as a consultant, writer, and trainer specializing in Office 365 and Exchange Server. Paul no longer writes for Practical365.com.

Comments

  1. Cathryn

    So, I have been fiddling with your script to do the following:
    Get the Username, OU with a specific format, and TotalItemSize in GB for all mailboxes over 50GB and then for each user in that list get the MailboxFolderStatistics including Oldest and Newest Items for only the single OldestItemReceivedDate and the foldername where that oldest item resides and export that to a .csv
    The first part runs spectacularly and pulls what I’m looking for. Where I’m having a problem is getting the Oldest Item Received Date and Folder Name to input into the second part and then exporting that to a .csv file.

    This is what I have so far – Any help is much appreciated!
    $mailboxes = @(Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Where-Object { $_.TotalItemSize -gt “50GB” } | Select DisplayName, @{expression={(Get-Recipient $_.DisplayName).OrganizationalUnit};name=”OrganizationalUnit”}, @{label=”TotalItemSize”;expression={[math]::Round(($_.TotalItemSize.value.ToString().Split(“(“)[1].Split(” “)[0].Replace(“,”,””)/1024MB),2)}})
    $report = “C:\Reports\Exchange\Test.csv”
    foreach ($mailbox in $mailboxes)
    {
    $inboxstats = Get-MailboxFolderStatistics $mailbox.DisplayName -IncludeOldestAndNewestItems | Select FolderName, OldestItemReceivedDate | Sort OldestItemReceivedDate | Where OldestItemReceiveddate -ne $null | Select-Object -First 1

    $mbObj = New-Object PSObject
    $mbObj | Add-Member -MemberType NoteProperty -Name “DisplayName” -Value $mailbox.DisplayName
    $mbObj | Add-Member -MemberType NoteProperty -Name “OU” -Value $mailbox.OrganizationalUnit
    $mbObj | Add-Member -MemberType NoteProperty -Name “TotalItemSize(GB)” -Value $mailbox.TotalItemSize
    $mbObj | Add-Member -MemberType NoteProperty -Name “FolderName” -Value $inboxstats.Name
    $mbObj | Add-Member -MemberType NoteProperty -Name “OldestItem” -Value $inboxstats.OldestItemReceivedDate
    $report += $mbObj
    }
    $report

    1. Avatar photo

      I don’t have an on-premises Exchange server any more, but this code works for Exchange Online. I don’t recommend creating a complex set of piped cmdlets because it makes it awfully difficult to understand code (at times) and creates a support issue going forward.

      $Report = [System.Collections.Generic.List[Object]]::new()
      [array]$Mailboxes = Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited | Sort-Object DisplayName
      ForEach ($Mbx in $Mailboxes) {
      $Stats = Get-MailboxStatistics -Identity $Mbx.Alias
      [float]$MbxSizeGB = [math]::Round(($Stats.TotalItemSize.value.ToString().Split(“(“)[1].Split(” “)[0].Replace(“,”,””)/1024MB),2)
      If ($MbxSizeGB -gt 50 ) {
      $FolderStats = Get-MailboxFolderStatistics -Identity $Mbx.Alias -IncludeOldestAndNewestItems | `
      Select-Object Name, OldestItemReceivedDate | Sort-Object OldestItemReceivedDate | `
      Where-Object OldestItemReceiveddate -ne $null | Select-Object -First 1
      $ReportLine = [PSCustomObject][Ordered]@{
      Mailbox = $Mbx.displayName
      ‘Size GB’ = $MbxSizeGB
      Folder = $FolderStats.name
      ‘Oldest item’ = $FolderStats.OldestItemReceivedDate
      }
      $Report.Add($ReportLine)
      }
      }

      $Report | Out-GridView

  2. Spain

    thank you
    I have improve your script with two lines

    echo $mailbox.PRIMARYSMTPADDRESS
    $inboxstats = Get-MailboxFolderStatistics $mailbox.PRIMARYSMTPADDRESS

  3. Nikhil

    Can we fetch inactive mailbox folder statistics? If yes, could you please help me?

  4. Brian

    How do I get size and item info for User Created folders and subfolders only? I can see the folders when I run get-mailboxfolderstatistics however I need to target a set of user created folders for the entire organization. I have over 18000 users I cant run a basic command and then parse the info out I need to get the folder info directly from my powershell command…is it even possible?

    1. Avatar photo

      If you have a defined set of folders that you need to grab information for, you can use the Graph API to fetch the folders and then parse them to find the target set (like I do for the Inbox in https://office365itpros.com/2022/05/19/mailbox-folder-statistics/). After that, it’s a matter of straightforward PowerShell to grab the statistics for those folders. Using the Graph with PowerShell is much faster than trying to do this with Get-ExoMailboxFolderStatistics…

  5. Alain Sylvestre

    HI,

    Is that script working with microsoft 365 today ?

  6. Jarno Jonkman

    Good morning, ,

    Does anyone know a solution for me?

    There are a number of users of exchange 2016 where the mailbox is too big.
    I want to reduce this, and now i would like an output (*csv) which contains the senders (or domains) and the total mb’s of the senders.
    I can’t so far, can anyone help?

    Thank you in advance
    Jarno

  7. boe dillard

    is there a single command to show a list of mailboxes usage and their archive usage in a SINGLE command instead of trying to combine two csv files?

  8. Sri

    Hi Paul, I am in need of generating a report consisting of “total item counts” of an Inbox, it’s subfolders, user-created folders, and subfolders of an O365 mailbox.

    I am using the below script. However, how to get just “total item counts” of all these folders.

    foreach ($f in (Get-Mailbox firstname.lastname*)) { Get-MailboxFolderStatistics $f
    .Name -FolderScope Inbox | select identity, itemsinfolder}

  9. Jojo

    I have a question and a sticky situation that just got dropped on my lap a few days ago. I have a user, who somehow has thousands of folders in his mailbox with zero data. How would I script Get-MailboxFolderStatistics while also passing through a command to delete the folders with zero data in them. Most of these are trash and need to be purged so we can migrate the mailbox from onprem to o365

  10. Ashton Hearon

    Thanks for some other great post. Where else may just anybody get that kind of information in such a perfect manner of
    writing? I have a presentation next week, and I’m
    on the look for such information.

  11. Choi Hyun Yong

    When encoding, system.object[] is output.Is there any way to take action?

  12. Brandy Blanchard

    Keep up the excellent piece of work, I read few articles on this site and I think that your web blog is real interesting and contains sets of excellent info.

  13. Antanas

    Hi,
    I lost about 870000 of emails in users mailbox …

    [PS] C:\WINDOWS\system32>Get-Mailbox arturas-ba| Get-MailboxFolderStatistics | Ft Name, ItemsInFolder

    Name ItemsInFolder
    —- ————-
    Top of Information Store 0

    Deleted Items 553

    Inbox 706

    Outbox 0

    Sent Items 5294

    Deletions 6438

    Total about 15000

    [PS] C:\WINDOWS\system32>Get-Mailbox userA | Get-MailboxStatistics | Select ItemCount

    ItemCount
    ———
    886785

    … any ideas ?

  14. Stuart

    Hi Paul,

    Is possible to calculate the number email based on Message Class? I need to produce a report for but a lot of users have created 100s of folders outside of the inbox. So if do a report of the whole inbox I need to filter it email items only.

  15. Shaun

    Something isn’t right :/

    Cannot process argument transformation on parameter ‘Identity’. Cannot convert the “Users Name” value of type
    “Deserialized.Microsoft.Exchange.Data.Directory.Management.Mailbox” to type
    “Microsoft.Exchange.Configuration.Tasks.GeneralMailboxOrMailUserIdParameter”.
    + CategoryInfo : InvalidData: (:) [Get-MailboxFolderStatistics], ParameterBindin…mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-MailboxFolderStatistics
    + PSComputerName : outlook.office365.com

    1. MikeC

      I get the same as Shaun. I’m wondering if commands have changed in the 5 years since he posted this. Hoping the author is still monitoring this and knows the answer. I would love for this script to work for me!

  16. Gregor

    HI,

    Great Script i Need to have number of contacts by user.
    So i Change your script when i use it manually
    Get-MailboxFolderStatistics alan.reed -FolderScope Contacts | Where {$_.FolderPath -eq “/Kontakte”} | Select Name,FolderandSubFolderSize,ItemsinFolderandSubfolders

    when i add this to script
    i get Errors

    You cannot call a method on a null-valued expression.
    At C:\temp\get-contacts_numbers.ps1:10 char:5
    + $mbObj | Add-Member -MemberType NoteProperty -Name “Contacts Size (Mb)” -Val …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    do you have some info?

    1. Avatar photo

      Perhaps the Get-MailboxFolderStatistics cmdlet is not returning any results with your modifications. You will need to debug your changes. Try running the command on its own in the Exchange Management Shell, see if it returns any results. Also check whether you’ve changed any variable names elsewhere in the script. If you’re still stuck, post your code somewhere public like GitHub or Pastebin and open a thread on Reddit in the /r/exchangeserver or /r/powershell areas so people can see your entire code and offer suggestions.

      1. Gregor

        i use german exchange and want to have number of all contacts also subfolders per mailbox. so it would be ok to have one line per user.
        the error is in the line where mailbox.displayname is.
        all lines till script return dates.

    2. Mahendra Reddy

      Please export the user’s alias to a CSV file with the below CMD:

      Get-Mailbox | ft Displayname, Alias >C:\Temp\userlist.csv

      Then use the below CMD and get the contacts per user:

      Import-Csv C:\Temp\userlist.csv | ForEach {Get-MailboxFolderStatistics -identity $_.Alias -FolderScope Contacts | Where {$_.FolderPath -eq “/Contacts”} | Select Name,FolderandSubFolderSize,ItemsinFolderandSubfolders } >C:\Temp\users_contacts.csv

      Later you can merge the data in both the excel files to get the final report.

  17. MartinF

    Hi great article. Everything is running fine until I hit Get-MailboxFolderStatistics (not recognised as the name of a cmdlet). Whereas a later call to Get-MailboxFolder works fine.

    I’m wondering if the cmdlet has been deprecated, or I have a strange version of MSOnline

    1. SpacemanSpiff

      Same thing as MartinF, not recognized. Also was able to obtain this info, which makes it seem like it is not allowed at the O365 level:
      Import-Session : Running the Get-Command command in a remote session returned no results.
      At line:1 char:1
      + Import-PSSession -Session $Session -Type Cmdlet -Name Get-MailboxFolderStatistic …
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidResult: (:) [Import-Session], ArgumentException
      + FullyQualifiedErrorId : ErrorNoResultsFromRemoteEnd,Microsoft.PowerShell.Commands.ImportPSSessionCommand

  18. Martin Kidd

    Is it possible to export the results to csv and show which OU the user resides in?

    1. MartinF

      Can’t see why not – if the information’s there. Exporting to a file should be straightforward using pipes (|).

  19. Alex

    If you want to get $_.FolderSize value represented in [decimal], please use following:

    $Folderstats = Get-MailboxFolderStatistics -identity $mailbox.Alias
    foreach ($folder in $Folderstats) {
    $s = $folder | Select-Object @{
    N = “FS_MB”;
    E = {
    [math]::round( ([decimal](($_.FolderSize -replace “[0-9.]+ [A-Z]* (([0-9,]+) bytes)”,”`$1″) -replace “,”,””) / 1MB),2)
    }
    }

  20. Alex

    Hi Paul

    It does not work for O365 EOL. Cause FolderAndSubfolderSize is a [String]

    Your script giving error:
    Method invocation failed because [System.String] does not contain a method named ‘ToMb’.

    PS C:UsersDocumentsScripts> Get-MailboxfolderStatistics | Get-member *size*

    TypeName: Deserialized.Microsoft.Exchange.Management.Tasks.MailboxFolderConfiguration

    Name MemberType Definition
    —- ———- ———-
    AuditFolderStubSize Property System.String {get;set;}
    FolderAndSubfolderSize Property System.String {get;set;}
    FolderSize Property System.String {get;set;}
    TopSubjectSize Property System.String {get;set;}

    Please try to update with following: http://stackoverflow.com/questions/38011372/exchange-get-mailboxfolderstatistics-foldersize-to-mb

  21. Adam C

    Hi Paul,

    Thanks for the great post,

    I have tried many variations of this and never managed to get it to work – currenty we are using Office365 and my code is: Get-Mailbox | Get-MailboxFolderStatistics | Where {$_.Name -match “Inbox”} | Select Identity, Name, ItemsInFolder | Sort-Object ItemsInFolder -descending | Export-csv c:InboxReport.csv

    The problem I have is that the ItemsInFolder count is always wrong, looking into it there is a microsoft article explaining why (https://support.microsoft.com/en-us/kb/3098973)

    Works perfectly for when I run it on Sent Items and Deleted Folders but never on the Inbox

    Do you have any ideas how I can get round this and get a true representation of the number of emails in a users inbox please?

    Thanks!

    A

  22. Rob Mulder

    Hi Paul,

    I just want a list of all folders under the root (not only Inbox, Outbox etc but also folders created by the user) but NO subfolders list. How do I do that?

    So, this but then without listing all the subfolders….
    Get-MailboxFolderStatistics robert.muhren | Select Name,FolderPath,FolderandSubFolderSize,ItemsinFolderandSubfolders | Sort-Object FolderandSubFolderSize

  23. Nicola

    I have 4 Exchange Databases (on different severs) and I would like a report that includes;

    Name
    Last Mailbox Logon
    Last Logon By
    Item Size (mb)
    Average Item Size (mb)
    Deleted Items Size (mb)
    No of Items.

    Any help would be great.

  24. Dan Au

    Hi there,

    Is there a way to script this where to find an email address that was stuckk in all domain users draft folder?

    Thanks
    Dan

  25. Kris Kirkbride

    Hi,

    Is there a way of JUST exporting the size and item count in the Inbox folder ONLY (not inbox subfolders) for all users in an entire organisation please??

  26. Ray Davis

    I have a question, I am trying to find a powershell script that will list out what the users have in sent item. Not the total sent, but what is a task item vs a stand email with a attachment.

    So like IPM.TASK and IPM.Note (examples) I wasn’t to see each sent email with a size and if its a task or not.

    Get-MailboxfolderStatistics username | select name, foldersize, itemsinFolder give me a overview.

    Is it possible how to determine this?

      1. Peter

        Paul

        All I want to do is create a report showing email address, total item count and mailbox size from a txt file containing a load of email addresses and output to a csv file. Any chance of a script for that?

        Thanks

        Peter

  27. Doug

    Is there a way to modify this to show all folders for all users?
    Evenif my server or by db that would work, but would like to have it all in one if possible.
    Thanks
    Doug

  28. Jake

    For those looking to report on multiple values, this is for Sent Items, Deleted Items, and Deletions:

    $mailboxes = @(Get-Mailbox -ResultSize Unlimited)
    $report = @()

    foreach ($mailbox in $mailboxes)
    {
    $mbObj = New-Object PSObject
    $mbObj | Add-Member -MemberType NoteProperty -Name “Display Name” -Value $mailbox.DisplayName

    $inboxstats = Get-MailboxFolderStatistics $mailbox -FolderScope SentItems | Where {$_.FolderPath -eq “/Sent Items”}
    $mbObj | Add-Member -MemberType NoteProperty -Name “Sent Items Size (Mb)” -Value $inboxstats.FolderandSubFolderSize.ToMB()
    $mbObj | Add-Member -MemberType NoteProperty -Name “Sent Items” -Value $inboxstats.ItemsinFolderandSubfolders

    $inboxstats = Get-MailboxFolderStatistics $mailbox -FolderScope DeletedItems | Where {$_.FolderPath -eq “/Deleted Items”}

    $mbObj | Add-Member -MemberType NoteProperty -Name “Deleted Item Size (Mb)” -Value $inboxstats.FolderandSubFolderSize.ToMB()
    $mbObj | Add-Member -MemberType NoteProperty -Name “Deleted Items” -Value $inboxstats.ItemsinFolderandSubfolders

    $inboxstats = Get-MailboxFolderStatistics $mailbox -FolderScope RecoverableItems | Where {$_.FolderPath -eq “/Deletions”}

    $mbObj | Add-Member -MemberType NoteProperty -Name “Deletions Item Size (Mb)” -Value $inboxstats.FolderandSubFolderSize.ToMB()
    $mbObj | Add-Member -MemberType NoteProperty -Name “Deletions Items” -Value $inboxstats.ItemsinFolderandSubfolders

    $report += $mbObj
    }

    $report | Export-CSV .MailboxSentDeletedDeletions.csv -NoType

    Created this thanks to Paul’s original script. Very nice job as always.

  29. Scott

    Please ignore my previous post as I figured out the problem. I’m trying to do something similar for the outbox where I just obtain a list of users who have items in the outbox. When I modify this I get a csv of all users and the users who don’t have anything in the outbox appear with a blank. How do I exclude those users and just get the users who have more than 0 items?

  30. Scott

    Does this work in Exchange Online? I get error messages

    At C:scriptsoutbox.ps1:10 char:5
    + $mbObj | Add-Member -MemberType NoteProperty -Name “Inbox Size (Mb)” -Value …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    Cannot process argument transformation on parameter ‘Identity’. Cannot convert value “User” to type “Microsoft.Exchange.Configuration.Tasks.GeneralMailboxOrMailUserIdParameter”. Error: “Cannot convert hashtable to an
    object of the following type: Microsoft.Exchange.Configuration.Tasks.GeneralMailboxOrMailUserIdParameter. Hashtable-to-Object conversion is not supported in restricted language mode or a Data section.”
    + CategoryInfo : InvalidData: (:) [Get-MailboxFolderStatistics], ParameterBindin…mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-MailboxFolderStatistics
    + PSComputerName : outlook.office365.com

    You cannot call a method on a null-valued expression.

  31. Laeeq Qazi

    Hi Paul,

    Please use
    Export-CSV inboxsizes.csv -NoTypeInformation
    instead of
    Export-CSV inboxsizes.csv
    to skip first unwanted row in output csv file.

    Kind Regards,
    Laeeq Qazi

  32. Robert

    Hey Paul,

    Is there a way to pull this kind of information but for all mail after a specific date? We are trying to get the item count and size of any mail that was sent to a user AFTER they were Disabled. There will be a list of several users and each user will have a different Disabled date.

    Thanks!

  33. Tony G

    Hi Paul,

    Thanks for replying so quick. Here is the output from PowerShell. It’s from a 2008 r2 server running Exchange 2007.

    Get-UMIPGateway | ForEach {If($_.OutCallsAllowed -Eq $False){ “Gateway Name = ” +$_.Name;ForEach ($HuntGroup In $_.Huntgroups){“Huntgroups ” + $Huntgroup}}}

    [PS] C:Windowssystem32>cd
    [PS] C:\>$mailboxes = @(Get-Mailbox -ResultSize Unlimited)
    [PS] C:\>$report = @()
    [PS] C:\>
    [PS] C:\>foreach ($mailbox in $mailboxes)
    >> {
    >> $inboxstats = Get-MailboxFolderStatistics $mailbox -FolderScope Inbox | Where {$_.FolderPath -eq “/Inbox” or “/Sent Items” or “/Deleted Items”}
    >>
    Unexpected token ‘or’ in expression or statement.
    At line:3 char:113
    + $inboxstats = Get-MailboxFolderStatistics $mailbox -FolderScope Inbox | Where {$_.FolderPath -eq “/Inbox” or <<< $mbObj = New-Object PSObject
    [PS] C:\> $mbObj | Add-Member -MemberType NoteProperty -Name “Display Name” -Value $mailbox.DisplayName
    [PS] C:\> $mbObj | Add-Member -MemberType NoteProperty -Name “Inbox Size (Mb)” -Value $inboxstats.FolderandSubFolderSize.ToMB()
    You cannot call a method on a null-valued expression.
    At line:1 char:120
    + $mbObj | Add-Member -MemberType NoteProperty -Name “Inbox Size (Mb)” -Value $inboxstats.FolderandSubFolderSize.ToMB <<< $mbObj | Add-Member -MemberType NoteProperty -Name “Inbox Items” -Value $inboxstats.ItemsinFolderandSubfolders
    [PS] C:\> $mbObj | Add-Member -MemberType NoteProperty -Name “Deleted Items Size (Mb)” -Value $Deletedstats.FolderandSubFolderSize.ToMB()
    You cannot call a method on a null-valued expression.
    At line:1 char:130
    + $mbObj | Add-Member -MemberType NoteProperty -Name “Deleted Items Size (Mb)” -Value $Deletedstats.FolderandSubFolderSize.ToMB <<< $mbObj | Add-Member -MemberType NoteProperty -Name “Deleted Items” -Value $Deletedstats.ItemsinFolderandSubfolders
    [PS] C:\> $mbObj | Add-Member -MemberType NoteProperty -Name “Sent Items Size (Mb)” -Value $inboxstats.FolderandSubFolderSize.ToMB()
    You cannot call a method on a null-valued expression.
    At line:1 char:125
    + $mbObj | Add-Member -MemberType NoteProperty -Name “Sent Items Size (Mb)” -Value $inboxstats.FolderandSubFolderSize.ToMB <<< $mbObj | Add-Member -MemberType NoteProperty -Name “Sent Items” -Value $SentItemsstats.ItemsinFolderandSubfolders
    [PS] C:\> $report += $mbObj
    [PS] C:\>}
    Unexpected token ‘}’ in expression or statement.
    At line:1 char:2
    + } <<<
    [PS] C:\>}

    1. Avatar photo

      Unexpected token ‘or’ in expression or statement.
      At line:3 char:113

      That’s the first error, the ‘or’ is unexpected. That error is causing the rest of the errors. Look at that first error, caused by the line of the script that runs right before the error is thrown.

      To give you a hint, you’re not using valid conditional operators.

  34. Tony G

    Hi Paul,

    I’ve been reading this page and it has really helped. I manage a network of 75 users and management wants Exchange reports. I’ve tested the script you have above for inbox items and size and it works great. I need to also include the Sent and Deleted Items folders in the same report. I tried copying the lines and just changing the folder names but received multiple errors.

    Here is a small snippet of what I’ve tried. Your assistance is greatly appreciated. Can you help?

    $report

    $mailboxes = @(Get-Mailbox -ResultSize Unlimited)
    $report = @()

    foreach ($mailbox in $mailboxes)
    {
    $inboxstats = Get-MailboxFolderStatistics $mailbox -FolderScope Inbox | Where {$_.FolderPath -eq “/Inbox” or “/Sent Items” or “/Deleted Items”}

    $mbObj = New-Object PSObject
    $mbObj | Add-Member -MemberType NoteProperty -Name “Display Name” -Value $mailbox.DisplayName
    $mbObj | Add-Member -MemberType NoteProperty -Name “Inbox Size (Mb)” -Value $inboxstats.FolderandSubFolderSize.ToMB()
    $mbObj | Add-Member -MemberType NoteProperty -Name “Inbox Items” -Value $inboxstats.ItemsinFolderandSubfolders
    $mbObj | Add-Member -MemberType NoteProperty -Name “Deleted Items Size (Mb)” -Value $Deletedstats.FolderandSubFolderSize.ToMB()
    $mbObj | Add-Member -MemberType NoteProperty -Name “Deleted Items” -Value $Deletedstats.ItemsinFolderandSubfolders
    $mbObj | Add-Member -MemberType NoteProperty -Name “Sent Items Size (Mb)” -Value $inboxstats.FolderandSubFolderSize.ToMB()
    $mbObj | Add-Member -MemberType NoteProperty -Name “Sent Items” -Value $SentItemsstats.ItemsinFolderandSubfolders
    $report += $mbObj

  35. Simon Hopkin

    Hi Paul,

    How would you modify your script to include only Inbox & Sent Items (Folder Size & Number of Items) in a single CSV.

    The scripts works great for all mailboxes pulling Inbox stats, I would like to include Sent Items in the same output.

  36. Pravar

    Hi Paul,

    Thanks. You saved my day. I have slightly changed the script to suit my requirement. However the output shows blank for the users who have multiple folders directly under Inbox. Am I missing something here and can I send this report by html e-mail? Thanks once again.

    $mailboxes = @(get-distributiongroupmember -Identity “Test” | get-mailbox)
    $report = @()

    foreach ($mailbox in $mailboxes)
    {
    $inboxstats = Get-MailboxFolderStatistics $mailbox -FolderScope Inbox

    $mbObj = New-Object PSObject
    $mbObj | Add-Member -MemberType NoteProperty -Name “Display Name” -Value $mailbox.DisplayName
    $mbObj | Add-Member -MemberType NoteProperty -Name “Folder Name” -Value $inboxstats.Name
    $mbObj | Add-Member -MemberType NoteProperty -Name “Folder Location” -Value $inboxstats.FolderPath
    $mbObj | Add-Member -MemberType NoteProperty -Name “Items in Folder” -Value
    $inboxstats.ItemsinFolder
    $report += $mbObj
    }

    $report

  37. bilson

    Do you know of a way to capture to total number of FOLDERS within a mailbox. All the PS commands I see are to get the total item count within a folder or mailbox.
    I am able to run
    Get-Mailbox -Database | Get-MailboxFolderStatistics | FT Identity, FolderPath -AutoSize
    and this will get me all the users and their individual folders and subfolders. I am looking to get a total folder count of this output per mailbox. can you suggest a way to script this?

  38. vinod

    Hi Paul,

    The script is awesome i need a script something like, the foldersize greater than 100 MB, when i write with the help of your script it is showing only one folder which is having highest size,not all folders greater than 100 mb..

  39. Ed Wilkinson

    Great script I changed it to include Sent
    I’m trying to add the Archive Sent folder size and Item count to the report with no luck. Comes back with 0 result. Any ideas.

    $mailboxes = @(Get-Mailbox -Resultsize Unlimited)
    $report = @()
    foreach ($mailbox in $mailboxes)
    {

    $sentstats = Get-MailboxFolderStatistics $mailbox -FolderScope SentItems | Where {$_.FolderPath -eq “/Sent Items”}

    $sentstatsa = Get-MailboxFolderStatistics $Mailbox -Archive -FolderScope SentItems | Where {$_.FolderPath -eq “/Sent Items”}

    $mbObj = New-Object PSObject
    $mbObj | Add-Member -MemberType NoteProperty -Name “Display Name” -Value $mailbox.DisplayName
    $mbObj | Add-Member -MemberType NoteProperty -Name “Sent Size (Mb)” -Value $sentstats.FolderandSubFolderSize.ToMB()
    $mbObj | Add-Member -MemberType NoteProperty -Name “Sent Items” -Value $sentstats.ItemsinFolderandSubfolders

    $mbObj | Add-Member -MemberType NoteProperty -Name “ArchSentSize (Mb)” -Value $sentstatsa.FolderandSubFolderSize.ToMB()
    $mbObj | Add-Member -MemberType NoteProperty -Name “Arch Sent Items” -Value $sentstatsa.ItemsinFolderandSubfolders

    $report += $mbObj
    }
    $report

  40. Graeme

    Hi Paul,

    I’m trying to do something that should be easier, return a simple numeric value for the number of items in the inbox of 1 particular mailbox. I want to use this to monitor a journal mailbox that our archiving software (Archive Manager) cleans out as it processes, so that we are alerted if there is a problem with it. This is the closest thing I’ve found, but it’s output doesn’t work for what I had in mind. Can you suggest a way to get the result I need?

  41. Sigmund

    Hi

    Is it possible to combine the command below with several Folders such as Inbox, Drafts, SentItems etc. ? And is there any way to count all Items togehter (if there are multiple folders) as a Total?

    Get-MailboxFolderStatistics alan.reid -FolderScope Inbox | Where {$_.FolderPath -eq “/Inbox”} | Select Name,FolderandSubFolderSize,ItemsinFolderandSubfolders

    Thanks in advance, Sigmund

  42. Saeed Mulla

    Hi,

    My setup has a live mailbox and an archive mailbox for each user (3000 users).

    I’m doing a exchange analysis report to see a list of all users with live quotas assigned, how much of that quotas is used along with total item count per mailbox as well as the matching archive mailbox also showing quota, used amount and item count in the same csv export.

    I’ve worked out how to do it per mailbox – but that means i have to find and match each user to archive mailbox csv sheet- which for a few users is OK- but for 3000 its a nightmare.

    Example of output i’m looking for:

    Alias | Email address | Live Quota | Live Used | Item count of live mailbox | Archive Quota | Archive Used | item count of archive mailbox

    Can you help?

  43. Andy M

    Hi Paul,

    Wonder if you can assist (I am very new to PS) – I am looking to list out each user Deleted Item size and count and found the following that work perfectly for individual user mailboxes

    “Get-MailboxFolderStatistics User.Name -FolderScope DeletedItems | Select Name,FolderSize,ItemsinFolder”

    Is they a way i can amend this command to run against all users mailboxes in a specific DB Store and output the same information

      1. Andy M

        Thanks for reply Paul – works a treat

        1. AAA

          Hi Andy,

          Can you please specify the exact command-let which you used for this task ?

          Thanks

  44. Mike

    Hi Paul,

    I realise that this is an old thread, so I’m hoping that you’re still checking it. I have modified your script to try to export a list of users, filtered by their SyncIssues folders. I’m not quite sure where my mistake is, however my csv file is blank except for the headings of Display Name, Size (MB), Inbox Items. The command runs without any errors, and I know for sure that SyncIssues folders do exist as I have tested.

    When I manually run the command below I get everything I need, for that one user. Would you please take a look at the script and tell me where I’m messing this up?

    Command that works:

    get-mailboxfolderstatistics “username” -folderscope syncissues | sort-object FolderSize -descending | FT foldertype, FolderSize, ItemsInFolder | export-csv “c:usersusernamedesktopsizes.csv”

    Modified Script that doesn’t work as expected:

    $mailboxes = (Get-Mailbox -ResultSize Unlimited)
    $report = @()
    foreach ($mailbox in $mailboxes)
    {
    $inboxstats = Get-MailboxFolderStatistics $mailbox -FolderScope SyncIssues
    $mbObj = New-Object PSObject
    $mbObj | Add-Member -MemberType NoteProperty -Name “Display Name” -Value $mailbox.FolderType
    $mbObj | Add-Member -MemberType NoteProperty -Name “Size (Mb)” -Value $inboxstats.FolderSize
    $mbObj | Add-Member -MemberType NoteProperty -Name “Inbox Items” -Value $inboxstats.ItemsinFolder
    $report += $mbObj
    }
    $report

    1. Mike

      Hi Paul,

      After some playing around with the code (and finding a forum that helped with the sorting), I have found a solution that appears to work. Have a good one.

      #This script queries the Exchange domain, filtering by mailboxes that contains a SyncIssues folder, and then displays them in descending order based on total size including subfolders
      #
      $mailboxes = @(Get-Mailbox -ResultSize Unlimited)
      $report = @()
      foreach ($mailbox in $mailboxes)
      {
      $inboxstats = Get-MailboxFolderStatistics $mailbox | Where {$_.FolderPath -eq “/Sync Issues”}
      $mbObj = New-Object PSObject
      $mbObj | Add-Member -MemberType NoteProperty -Name “Display Name” -Value $mailbox.DisplayName
      $mbObj | Add-Member -MemberType NoteProperty -Name “Folder Type” -Value $inboxstats.FolderType
      $mbObj | Add-Member -MemberType NoteProperty -Name “Size (Mb)” -Value $inboxstats.FolderandSubFolderSize
      $report += $mbObj
      }
      $report | Sort-Object “Size (Mb)” -descending
      $report

    2. Avatar photo

      One problem with that first attempt is that you’re piping through Format-Table (FT) then trying to pipe to Export-CSV.

      Basically you should only pipe to Format-* cmdlets if you want to display results in your PowerShell console. If you plan to pipe objects to other cmdlets then don’t send to Format-* first.

      I suspect your first attempt would have worked by replacing FT with Select-Object instead.

  45. TRAN XUAN QUANG

    I alos used the command below to delete all contact in mailbox, but it is not success.

    search-mailbox -identity USERNAME -searchquery kind:contacts -deletecontent

    Please help me to delete all contact on user mailbox.

    THanks

  46. TRAN XUAN QUANG

    I get mailbox contact folder, the contact folder has alot of items, I want to delete all of contact. Please help me to resolve the issue.
    thanks

  47. Chris

    Ok, Good luck!

    😉

  48. Kshreek

    We need a script to examine each mailbox to determine its size, the number of items and the items in the mailbox that exceed 20MB. . This script needs to be able to be run by group, and by city and by DB.

  49. abdul

    You cannot call a method on a null-valued expression

  50. mike

    sorry, example:
    Get-MailboxFolderStatistics user1 -FolderScope Inbox | Where {$_.FolderPath -eq “/Inbox”} | Select Name,FolderandSubFolderSize,ItemsinFolderandSubfolders | export-csv c:file.csv

    If I want to sub a csv file with a list of users in place of user1

  51. mike

    Great writeup!
    I need to gather some folder stats for a certain list of people. I have tried various times using import-csv and get-content, but cannot figure out how to make it work. If I have a certain list of users and need to export stats (name, foldersize, itemsinfolder) to a csv file, how do I constuct the command?

    Obviously I can still trying to master powershell, so any help is appreicated. Thanks!

  52. abhishek

    Can We get count of messages of user in inbox from specific date range through Get-MailboxStatistics & Get-MailboxFolderStatistics.

  53. jason

    Hi Paul,

    in your last steps above, – report of the inbox sizes for all mailboxes in the organizations – any way to add unread items also?

    Thank you.

  54. Ruixia Zhang

    Hi Paul,
    I have a question to ask,the description is as followed:
    First,I new a mailbox,then enable archive box,but when I excute
    get-mailboxstatistics ccc -archive
    get the result: ItemCount :1
    Meanwhile,I login this user by owa only to find {In-Place Archive – ccc} is empty.So, How can I view this user’archive directory in my computer ?

  55. Blue Devil

    Excellent post! Is there a way to combine the report? On a single CSV I want to show Inbox Size, Deleted Item Size, Sent Items Size and Calendar Items Size? Is that possible? if it how do it do it? Thank you again for this great post.

  56. Abdul Wajid

    Dear Anand,

    I get your point. It is showing the results but it is not serving my purpose. Any other way to get the item counts in the mailbox and sort them with time stamp or something so it might help us. Just need to get the number of items received in 2013. There is a time stamp on the mail items and we can sort them out in outlook. There maybe a way of getting this information.

    Thanks for your help

    Regards
    Abdul Wajid

  57. Anand

    Abdul,

    What this Command will do, let me tell you–
    This will query the transport logs for the particular recipients. But this purely depends upon the retention period of the transport logs.
    If the logs are just 15 days or 30 days old, and if you query for an email that has been sent 3 months back, it will not give you the result.

    The start time should be within the range of retention.
    Try the below command by giving any recent date/time.. it’ll give you output.
    Get-TransportServer | Get-MessaqgeTrackingLog -Recipients “Name” -EventtId Receive -Start “12/30/2010 8:00:00 AM” -End “12/31/2010 5:00:00 PM”

  58. Anand

    Abdul,

    Yes thats Possible!! Use the below command–

    Get-TransportServer | Get-MessaqgeTrackingLog -Sender “SenderName” -EventtId Receive -Start “12/30/2010 8:00:00 AM” -End “12/31/2010 5:00:00 PM”

    1. Abdul Wajid

      Dear Anand,

      Good Day,

      Thank you very much for the answer. I tried but it didn’t give any output. My actual requirement is as follows:

      I want to get the message count for received items for a exchange mailbox, that is the number of emails received by a user in a date range.

      Thank You

      Regards

  59. Abdul Wajid

    i WANT TO GET NUMBER OF EMAILS RECEIVED BY A SPECIFIC USER IN A SPECIFIC Date range.

    Any possibility?

    Thank You

  60. Hector Fonseca

    Hi Paul.
    Excelent Post. So, How I can export the report to csv file?.

    1. Andy

      Type at the end of the command line this:
      | Export-Csv C:”Path to folder”Exported.csv

  61. Anand

    Paul,

    I want information such as Mailboxes deleted per Month, Number of Public Folders Deleted per month with size, Public Folders Converted to Mailbox per month. Can you help me out in this?

    I am able to retrieve information about addition of mailbox/PF, but deletion seems to be a tough one for me.

    Thanks in Advance 🙂

  62. Aasmir

    Hi Paul,

    another great TIP, I am trying to add permissions as well. I mean I want to see

    Name, FolderPath, Delegate, AccessRights.

    any suggestion how to combine them ?

    Many Thanks

  63. Mohammad Ali

    Hi Paul,

    I ran the script and in the output file, for few users am not getting item counts instead of getting “BLANK” even though they are visible in GAL.

    I checked the object and every thing seems to be good.

  64. Bradley

    Hi Paul, I am using your script to output the report in the post which is very helpful, but I would like to include some more information in my output results. As well as the inbox I would also like this information for the sent items, deleted items and a total size of the users mailbox all on the csv file.

    How would I do this please?

    Thank you

  65. Anant

    Hi,

    I am using

    get-mailbox abc@domain.com,xyz@domain.com

    get-mailbox abc@domain.com;xyz@domain.com

    get-mailbox -identity abc@domain.com,xyz@domain.com

    nothing is working. I want output of specific two mailboxes.

    Please suggest.

    Thanks

  66. Ramanathan

    I have list of users and need to find out whether they have mail items that are older than 6 months in exchange 2010.

    1. Katherine Bargas

      I would appreciate it is someone know how to do what Ramanathan is asking. I also need to find a script where I can target the INBOX and tell management how many of the email messages is older than X days. Has there been someone who is good with programming that knows how to get this information?

      1. Avatar photo
  67. Ty

    Hi Paul, what if I want to see only the root folders under the mailbox? I have a user who has a great amount of subfolders including old System Cleanup folders from Exchange 2003 that show subfolders with the same names as the current root folders and subfolders. I’m worried that when I send the user this solid list that doesn’t show which folders are root folders, they will be confused.

    Thanks!

    Ty

      1. Ty

        Sweet! That will clear things up. Thanks Paul!

  68. Joe

    Hi Paul,

    Excellent post. What command should I substitute on your Inbox script for Sent items?

    I want to tell our email users to archive their Sent items, but I want to find out the size of their sent items first.

    Thanks,
    Joe

  69. lennys

    how about to combine with msg tracking log with certain folder like ‘Outbox’ or ‘Sent Items’. normally i use as per Exchangeserverpro notes :

    Get-MessageTrackingLog -Start “7/10/2012 08:00:00” -End “7/10/2012 18:00:00″ | Select-Object eventid,sender,timestamp,@{Name=”Recipients”;Expression={$_.recipients}},@{Name=”RecipientStatus”;Expression={$_.recipientstatus}},messagesubject -ResultSize unlimited | Export-CSV c:scriptslog6.csv

    AND

    $msgs = Get-TransportServer | Get-MessageTrackingLog -Sender Tom@exchangeserverpro.net -Recipients Alan.Reid@exchangeserverpro.net | Select-Object eventid,sender,timestamp,@{Name=”Recipients”;Expression={$_.recipients}},@{Name=”RecipientStatus”;Expression={$_.recipientstatus}},messagesubject | export-csv c:scriptslog10.csv

    is it possible to combine with specific folders?

    tq

      1. lennys

        Hi Paul,
        my apology on my question is quite not clear. What im trying to get is a command which we could able to see the total size in Inbox folder (or any folder), as well as list of email resides in the Inbox folder with certain date specified.

        Hopes this clear to you. Tx in advance for any info you may provide.

  70. amit

    Really Helpful

    1. Jojo

      I have a question and a sticky situation that just got dropped on my lap a few days ago. I have a user, who somehow has thousands of folders in his mailbox with zero data. How would I script Get-MailboxFolderStatistics while also passing through a command to delete the folders with zero data in them. Most of these are trash and need to be purged so we can migrate the mailbox from onprem to o365

Leave a Reply