mailbox size and items powershell
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..
November 4th, 2011 12:15pm
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
Free Windows Admin Tool Kit Click here and download it now
November 4th, 2011 12:59pm
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$_"})
November 4th, 2011 4:42pm
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$_"})
Free Windows Admin Tool Kit Click here and download it now
November 4th, 2011 11:31pm
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
November 5th, 2011 8:38pm
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
Free Windows Admin Tool Kit Click here and download it now
November 5th, 2011 9:55pm
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
November 7th, 2011 4:59am
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.
Free Windows Admin Tool Kit Click here and download it now
November 7th, 2011 11:19am
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
November 7th, 2011 11:34am
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
Free Windows Admin Tool Kit Click here and download it now
November 7th, 2011 1:52pm
You can use Karl's script, this will not have this issue.
smart
November 8th, 2011 12:28am
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",
Free Windows Admin Tool Kit Click here and download it now
November 8th, 2011 8:48am
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$_"})
November 8th, 2011 10:07am
You are welcomeMy Blog: http://unlockpowershell.wordpress.com
My Book:
Windows PowerShell 2.0 Bible
My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
November 8th, 2011 1:17pm
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.
Free Windows Admin Tool Kit Click here and download it now
November 17th, 2011 3:08pm
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
November 17th, 2011 4:37pm
thanks. but how does that fit into the original script? just copy and paste?
Free Windows Admin Tool Kit Click here and download it now
November 18th, 2011 7:54am
so just putting the new lines in the script doesnt work.
November 18th, 2011 8:00am
Can you put here what you have so far so we can troubleshoot it?
What error are you getting?http://LetsExchange.blogspot.com
Free Windows Admin Tool Kit Click here and download it now
November 18th, 2011 8:33am
$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?
November 18th, 2011 8:46am
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
Free Windows Admin Tool Kit Click here and download it now
November 18th, 2011 8:55am
thank you. OK, the script runs but the SentItemsSize is all 0's in the column.
November 18th, 2011 9:52am
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
Free Windows Admin Tool Kit Click here and download it now
November 18th, 2011 9:58am
so far so good - looks awesome. thank you.
November 18th, 2011 10:13am
You're welcome! We're here to help! :)http://LetsExchange.blogspot.com
Free Windows Admin Tool Kit Click here and download it now
November 18th, 2011 10:25am
route6688;
Not sure why you unmarked my answers as they were proper answers for your origianl question and followup.
KarlMy Blog: http://unlockpowershell.wordpress.com
My Book:
Windows PowerShell 2.0 Bible
My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
November 22nd, 2011 3:44pm