locked
mailbox size and items powershell RRS feed

  • Question

  • i'm looking for a powershell that can get me mailboxes over 400 megs, alias, display name, Total Item Size, Deleted Item Count, Total Deleted Item Size and server in text file or sreadsheet.

    we use exch 2007

     

    thanks..

    Friday, November 4, 2011 4:04 PM

Answers

  • Oh! Sorry, my mistake... I am using the Alias when it hasn't been "saved" to that variable yet and the $AllLargeMailboxes += (...) is in the wrong place as well... Replace it with this for example:

    $LargeMailboxes = Get-MailboxServer |% {Get-MailboxStatistics -Server $_.Name | Where-Object -FilterScript {$_.TotalItemSize.Value.ToMB() -gt "400"}}
    $AllLargeMailboxes = @()
    
    ForEach ($LargeMailbox in $LargeMailboxes)
    {
    	$MailboxObject = "" | Select-Object "Alias","Department","Display Name","Total Item Size (MB)","Deleted Item Count","Total Deleted Item Size (MB)","Server", "Total Sent Items", "Sent Items Size (MB)"
    
    	$MailboxObject.Alias = (Get-Mailbox -Identity $LargeMailbox.DisplayName).Alias
    	$MailboxObject.Department = (Get-User -Identity $LargeMailbox.DisplayName).Department
    	$MailboxObject."Display Name" = $LargeMailbox.DisplayName
    	$MailboxObject."Total Item Size (MB)" = $LargeMailbox.TotalItemSize.Value.ToMB()
    	$MailboxObject."Deleted Item Count" = $LargeMailbox.DeletedItemCount
    	$MailboxObject."Total Deleted Item Size (MB)" = $LargeMailbox.TotalDeletedItemSize.Value.ToMB()
    	$MailboxObject.Server =  $LargeMailbox.ServerName
    	
    	$mbSentStats = Get-MailboxFolderStatistics $MailboxObject.Alias | Where {$_.FolderPath -eq "/Sent Items"} | Select ItemsInFolderAndSubfolders, @{name="SentItemsSize";expression={$_.FolderAndSubfolderSize.ToMB()}}
    	$MailboxObject."Total Sent Items" = $mbSentStats.ItemsInFolderAndSubfolders
    	$MailboxObject."Sent Items Size (MB)" = [math]::round($mbSentStats.SentItemsSize, 2)
    	
    	$AllLargeMailboxes += $MailboxObject
    }
    
    $AllLargeMailboxes | Export-Csv -Path C:\scripts\report.csv -NoTypeInformation
    



    http://LetsExchange.blogspot.com
    • Marked as answer by route6668 Friday, November 18, 2011 3:09 PM
    Friday, November 18, 2011 2:54 PM

All replies

  • Try this one. It will retun all the mailboxes sort it based on size in excel :)

    get-mailbox -resultsize Unlimited | get-mailboxstatistics | select-object Alias,Displayname, @{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}}, @{label="TotalDeletedItemSize(MB)";expression={$_.TotalDeletedItemSize.Value.ToMB()}},DeletedItemCount | export-csv c:\report.csv
    
    


    Jasjit Singh Dhindsa | ITIL v3 | IASA Foundation Certified | MCITP:EMA Exchange 2010/2007 | MCTS:OCS 2007 | Exchange 2010/2007 | MCSA:Messaging/Security | MCSE:Messaging/Security
    Friday, November 4, 2011 4:48 PM
  • I'd do it like this:

    $LargeMailboxes = Get-MailboxServer |% {Get-MailboxStatistics -Server $_.Name | Where-Object -FilterScript {$_.TotalItemSize.Value.ToMB() -gt "400"}}
    $AllLargeMailboxes = @()
    foreach ($LargeMailbox in $LargeMailboxes)
    {
    $MailboxObject = "" | Select-Object "Alias","Display Name","Total Item Size (MB)","Deleted Item Count","Total Deleted Item Size (MB)","Server"
    $MailboxObject.Alias = (Get-Mailbox -Identity $LargeMailbox.DisplayName).Alias
    $MailboxObject."Display Name" = $LargeMailbox.DisplayName
    $MailboxObject."Total Item Size (MB)" = $LargeMailbox.TotalItemSize.Value.ToMB()
    $MailboxObject."Deleted Item Count" = $LargeMailbox.DeletedItemCount
    $MailboxObject."Total Deleted Item Size (MB)" = $LargeMailbox.TotalDeletedItemSize.Value.ToMB()
    $MailboxObject.Server =  $LargeMailbox.ServerName
    $AllLargeMailboxes += $MailboxObject
    }
    $AllLargeMailboxes | Export-Csv -Path C:\scripts\report.csv -NoTypeInformation

    Karl


    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    • Proposed as answer by Evan LiuModerator Monday, November 7, 2011 9:31 AM
    • Marked as answer by route6668 Tuesday, November 8, 2011 1:39 PM
    • Unmarked as answer by route6668 Tuesday, November 8, 2011 1:44 PM
    • Unproposed as answer by route6668 Tuesday, November 8, 2011 1:44 PM
    • Proposed as answer by Naomi N Thursday, December 8, 2011 8:27 PM
    Friday, November 4, 2011 8:31 PM
  • Both of these answers will give you what you need.

    As a last note, to easier filter the mailboxes, you can also do something like:

    Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | ? {$_.TotalItemSize -gt 500MB} | (...)
    

    very similar to what Karl suggested.


    http://LetsExchange.blogspot.com
    Sunday, November 6, 2011 1:33 AM
  • I agree with Nuno. If we combine the filter suggested the final command will be as listed below

     

    Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | ? {$_.TotalItemSize -gt 500MB} | select-object Alias,Displayname, @{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}}, @{label="TotalDeletedItemSize(MB)";expression={$_.TotalDeletedItemSize.Value.ToMB()}},DeletedItemCount | export-csv c:\report.csv
    

     


    Jasjit Singh Dhindsa | ITIL v3 | IASA Foundation Certified | MCITP:EMA 2010/2007 | MCTS:Messaging&OCS 2007 | MCSA:M&S | MCSE:M&S
    Sunday, November 6, 2011 2:50 AM
  • Yes, these two scripts are very good, I think they can help on your required.

     

    When you use Jasjit’s script, you can change the mailbox filter to what you required,  you also can add “-NoTypeInformation” to omits the type information from the CSV file

     

    Thanks,

     

    Evan

     

    Monday, November 7, 2011 9:54 AM
    Moderator
  • thaks guys this is working for me:

     

    Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | ? {$_.TotalItemSize -gt 400MB} | select-object Alias,Displayname, @{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}}, @{label="TotalDeletedItemSize(MB)";expression={$_.TotalDeletedItemSize.Value.ToMB()}},DeletedItemCount | export-csv c:\report.csv

    but...is there away to capture, in the same script, the Department attribute? I treid adding in with the Alias and Display name to no avail.

    Monday, November 7, 2011 4:15 PM
  • Use this

     

    Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | ? {$_.TotalItemSize -gt 400MB} | select-object Alias,Displayname,@{Name="Department";expression={(get-user $_.alias).department}}, @{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}}, @{label="TotalDeletedItemSize(MB)";expression={$_.TotalDeletedItemSize.Value.ToMB()}},DeletedItemCount | export-csv c:\report.csv
    


    Jasjit Singh Dhindsa | ITIL v3 | IASA Foundation Certified | MCITP: EMA 2010/2007 | MCTS: MES 2010/2007, OCS 2007 | MCSA: M+S | MCSE: M+S
    Monday, November 7, 2011 4:31 PM
  • so two things running the script with Department in it:

    1) I'm getting the Result size warning - even though its specified.

    WARNING: By default only the first 1000 items are returned. To change the number of items returned, specify the parameter "-ResultSize". To return all items specify "-ResultSize
    Unlimited" (Note: Returning all items may take a very long time and consume a large amount of memory depending on the actual number of items). It is not recommended to store the
    results in a variable; instead pipe the results to another task or script to perform batch changes.

    2) Doesnt populate.

     

    thanks

    Monday, November 7, 2011 6:49 PM
  • You can use Karl's script, this will not have this issue.

    smart

    Tuesday, November 8, 2011 5:25 AM
  • the only thing Karl's script doesnt give me is the Department? How would I add that in there? what I have tried so far isnt working. I got the ,, to show but not the data.

    here is the output:

     

    "Alias","Department","Display Name","Total Item Size (MB)","Deleted Item Count","Total Deleted Item Size (MB)","Server"
    "First.Last",,"Last, First","486","3208","214",

    • Edited by route6668 Tuesday, November 8, 2011 1:55 PM
    Tuesday, November 8, 2011 1:45 PM
  • Try this:

    $LargeMailboxes = Get-MailboxServer |% {Get-MailboxStatistics -Server $_.Name | Where-Object -FilterScript {$_.TotalItemSize.Value.ToMB() -gt "400"}}
    $AllLargeMailboxes = @()
    foreach ($LargeMailbox in $LargeMailboxes)
    {
    $MailboxObject = "" | Select-Object "Alias","Department","Display Name","Total Item Size (MB)","Deleted Item Count","Total Deleted Item Size (MB)","Server"
    $MailboxObject.Alias = (Get-Mailbox -Identity $LargeMailbox.DisplayName).Alias
    $MailboxObject.Department = (Get-User -Identity $LargeMailbox.DisplayName).Department
    $MailboxObject."Display Name" = $LargeMailbox.DisplayName
    $MailboxObject."Total Item Size (MB)" = $LargeMailbox.TotalItemSize.Value.ToMB()
    $MailboxObject."Deleted Item Count" = $LargeMailbox.DeletedItemCount
    $MailboxObject."Total Deleted Item Size (MB)" = $LargeMailbox.TotalDeletedItemSize.Value.ToMB()
    $MailboxObject.Server =  $LargeMailbox.ServerName
    $AllLargeMailboxes += $MailboxObject
    }
    $AllLargeMailboxes | Export-Csv -Path C:\scripts\report.csv -NoTypeInformation
    

    Karl

     


    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    • Marked as answer by route6668 Tuesday, November 8, 2011 4:40 PM
    • Unmarked as answer by route6668 Friday, November 18, 2011 12:40 PM
    • Proposed as answer by Naomi N Thursday, December 8, 2011 8:28 PM
    Tuesday, November 8, 2011 3:03 PM
  • thank you sir
    • Edited by route6668 Tuesday, November 8, 2011 4:40 PM
    Tuesday, November 8, 2011 4:40 PM
  • You are welcome
    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    Tuesday, November 8, 2011 6:14 PM
  • Karl, quick question. how do I add into the script to grab the size of a folder in MB's say like Deleted Items? I'm trying to fiddle with but havent been able to get the column to fill in.
    Thursday, November 17, 2011 8:04 PM
  • You can add something like:

    $mbDeletedStats = Get-MailboxFolderStatistics $MailboxObject.Alias | Where {$_.FolderPath -eq "/Deleted Items"} | Select ItemsInFolderAndSubfolders, @{name="DeletedItemsSize";expression={$_.FolderAndSubfolderSize.ToMB()}}
    
    $MailboxObject."Total Deleted Items" = $mbDeletedStats.ItemsInFolderAndSubfolders
    $MailboxObject."Deleted Items Size (MB)" = [math]::round($mbDeletedStats.DeletedItemsSize, 2)
    


    http://LetsExchange.blogspot.com
    Thursday, November 17, 2011 9:32 PM
  • thanks. but how does that fit into the original script? just copy and paste?
    Friday, November 18, 2011 12:49 PM
  • so just putting the new lines in the script doesnt work.
    Friday, November 18, 2011 12:55 PM
  • Can you put here what you have so far so we can troubleshoot it?

    What error are you getting?


    http://LetsExchange.blogspot.com
    Friday, November 18, 2011 1:30 PM
  • $LargeMailboxes = Get-MailboxServer |% {Get-MailboxStatistics -Server $_.Name | Where-Object -FilterScript {$_.TotalItemSize.Value.ToMB() -gt "400"}}
    $AllLargeMailboxes = @()
    foreach ($LargeMailbox in $LargeMailboxes)
    {
    $MailboxObject = "" | Select-Object "Alias","Department","Display Name","Total Item Size (MB)","Deleted Item Count","Total Deleted Item Size (MB)","Server"
    $MailboxObject.Alias = (Get-Mailbox -Identity $LargeMailbox.DisplayName).Alias
    $MailboxObject.Department = (Get-User -Identity $LargeMailbox.DisplayName).Department
    $MailboxObject."Display Name" = $LargeMailbox.DisplayName
    $MailboxObject."Total Item Size (MB)" = $LargeMailbox.TotalItemSize.Value.ToMB()
    $MailboxObject."Deleted Item Count" = $LargeMailbox.DeletedItemCount
    $MailboxObject."Total Deleted Item Size (MB)" = $LargeMailbox.TotalDeletedItemSize.Value.ToMB()
    $MailboxObject.Server =  $LargeMailbox.ServerName
    $AllLargeMailboxes += $MailboxObject
    }
    $AllLargeMailboxes | Export-Csv -Path C:\scripts\report.csv -NoTypeInformation
    

     

    $mbDeletedStats = Get-MailboxFolderStatistics $MailboxObject.Alias | Where {$_.FolderPath -eq "/Deleted Items"} | Select ItemsInFolderAndSubfolders, @{name="DeletedItemsSize";expression={$_.FolderAndSubfolderSize.ToMB()}}
    
    $MailboxObject."Total Deleted Items" = $mbDeletedStats.ItemsInFolderAndSubfolders
    $MailboxObject."Deleted Items Size (MB)" = [math]::round($mbDeletedStats.DeletedItemsSize, 2)
    

    I dont how to fit the two together and still get the original results with the new results. or should there be two scripts and just merge the csv files manually after the fact?

    Friday, November 18, 2011 1:42 PM
  • You just have them in the wrong place   :)

    Try the following (I changed the script to report the stats for the Sent Items folder, but you can check any folder!):

    $LargeMailboxes = Get-MailboxServer |% {Get-MailboxStatistics -Server $_.Name | Where-Object -FilterScript {$_.TotalItemSize.Value.ToMB() -gt "400"}}
    $AllLargeMailboxes = @()
    
    ForEach ($LargeMailbox in $LargeMailboxes)
    {
    	$MailboxObject = "" | Select-Object "Alias","Department","Display Name","Total Item Size (MB)","Deleted Item Count","Total Deleted Item Size (MB)","Server", "Total Sent Items", "Sent Items Size (MB)"
    
    	$mbSentStats = Get-MailboxFolderStatistics $MailboxObject.Alias | Where {$_.FolderPath -eq "/Sent Items"} | Select ItemsInFolderAndSubfolders, @{name="SentItemsSize";expression={$_.FolderAndSubfolderSize.ToMB()}}
    
    	$MailboxObject.Alias = (Get-Mailbox -Identity $LargeMailbox.DisplayName).Alias
    	$MailboxObject.Department = (Get-User -Identity $LargeMailbox.DisplayName).Department
    	$MailboxObject."Display Name" = $LargeMailbox.DisplayName
    	$MailboxObject."Total Item Size (MB)" = $LargeMailbox.TotalItemSize.Value.ToMB()
    	$MailboxObject."Deleted Item Count" = $LargeMailbox.DeletedItemCount
    	$MailboxObject."Total Deleted Item Size (MB)" = $LargeMailbox.TotalDeletedItemSize.Value.ToMB()
    	$MailboxObject.Server =  $LargeMailbox.ServerName
    	$AllLargeMailboxes += $MailboxObject
    	$MailboxObject."Total Sent Items" = $mbSentStats.ItemsInFolderAndSubfolders
    	$MailboxObject."Sent Items Size (MB)" = [math]::round($mbSentStats.SentItemsSize, 2)
    }
    
    $AllLargeMailboxes | Export-Csv -Path C:\scripts\report.csv -NoTypeInformation
    



    http://LetsExchange.blogspot.com
    Friday, November 18, 2011 1:51 PM
  • thank you. OK, the script runs but the SentItemsSize is all 0's in the column.
    Friday, November 18, 2011 2:48 PM
  • Oh! Sorry, my mistake... I am using the Alias when it hasn't been "saved" to that variable yet and the $AllLargeMailboxes += (...) is in the wrong place as well... Replace it with this for example:

    $LargeMailboxes = Get-MailboxServer |% {Get-MailboxStatistics -Server $_.Name | Where-Object -FilterScript {$_.TotalItemSize.Value.ToMB() -gt "400"}}
    $AllLargeMailboxes = @()
    
    ForEach ($LargeMailbox in $LargeMailboxes)
    {
    	$MailboxObject = "" | Select-Object "Alias","Department","Display Name","Total Item Size (MB)","Deleted Item Count","Total Deleted Item Size (MB)","Server", "Total Sent Items", "Sent Items Size (MB)"
    
    	$MailboxObject.Alias = (Get-Mailbox -Identity $LargeMailbox.DisplayName).Alias
    	$MailboxObject.Department = (Get-User -Identity $LargeMailbox.DisplayName).Department
    	$MailboxObject."Display Name" = $LargeMailbox.DisplayName
    	$MailboxObject."Total Item Size (MB)" = $LargeMailbox.TotalItemSize.Value.ToMB()
    	$MailboxObject."Deleted Item Count" = $LargeMailbox.DeletedItemCount
    	$MailboxObject."Total Deleted Item Size (MB)" = $LargeMailbox.TotalDeletedItemSize.Value.ToMB()
    	$MailboxObject.Server =  $LargeMailbox.ServerName
    	
    	$mbSentStats = Get-MailboxFolderStatistics $MailboxObject.Alias | Where {$_.FolderPath -eq "/Sent Items"} | Select ItemsInFolderAndSubfolders, @{name="SentItemsSize";expression={$_.FolderAndSubfolderSize.ToMB()}}
    	$MailboxObject."Total Sent Items" = $mbSentStats.ItemsInFolderAndSubfolders
    	$MailboxObject."Sent Items Size (MB)" = [math]::round($mbSentStats.SentItemsSize, 2)
    	
    	$AllLargeMailboxes += $MailboxObject
    }
    
    $AllLargeMailboxes | Export-Csv -Path C:\scripts\report.csv -NoTypeInformation
    



    http://LetsExchange.blogspot.com
    • Marked as answer by route6668 Friday, November 18, 2011 3:09 PM
    Friday, November 18, 2011 2:54 PM
  • so far so good - looks awesome. thank you.
    Friday, November 18, 2011 3:09 PM
  • You're welcome! We're here to help!   :)
    http://LetsExchange.blogspot.com
    Friday, November 18, 2011 3:21 PM
  • route6688;

    Not sure why you unmarked my answers as they were proper answers for your origianl question and followup.

    Karl


    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    Tuesday, November 22, 2011 8:40 PM
  • Hey everyone,

    Is there a way to get this script to send an email to a specific address?

    Wednesday, February 20, 2013 3:14 AM
  • Hi RhodanNZ,

    You can create a nice HTML e-mail with the data from the script (something like this: http://gallery.technet.microsoft.com/scriptcenter/Distributing-Mailboxes-e4e6b311).

    However, the quickest and easiest way is to just export everything to a file and then send that file attached. Using the example above, add the following to the end of the script:

    Send-MailMessage -From "admin@domain.com" -To "user@domain.com" -Subject "Big Mailboxes Report" -Attachments "C:\scripts\report.csv" -SMTPserver "smtp.domain.com" -DeliveryNotificationOption onFailure

    http://LetsExchange.blogspot.com

    Thursday, February 21, 2013 3:02 PM
  • i'm looking for a powershell that can get me mailboxes over 400 megs, alias, display name, Total Item Size, Deleted Item Count, Total Deleted Item Size and server in text file or sreadsheet.

    we use exch 2007

    thanks..

    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 11:49 AM