RFEMHelpdesk
asked on
Exchange 2010 Script
We are quickly running out of space on our Exchange 2010 server and I need to be able to identify the following data in Powershell using a script. I would then like to be able to run this script weekly to generate an automated email with a CSV file defining the size of all mailboxes in the environment with specifics concerning the items and sizes of the following:
The overall item count in the mailbox
The overall size in MB and/or GB of the mailbox
The overall item count in the Deleted Items folder
The overall size in MB and/or GB of the Deleted Items folder
The overall item count in the Sent Items folder
The overall size in MB and/or GB of the Sent Items folder
I have come up with the following script by cutting and pasting numerous different source codes. The Total and Deleted functions are working but, I cannot get the Sent items to function or generate any data. Additionally, Is there a way to combine results from both mail servers?
Any and all help would be greatly appreciated.
SCRIPT FOLLOWS:
Get-MailboxStatistics -Server MAIL|
Sort-Object -Property TotalItemSize -Descending |
Select-Object -property DisplayName,@{N="ItemCount ";E={$_.It emCount}},
@{N="TotalItemSize";E={$_. TotalItemS ize}},
@{N="deletedItemCount";E={ $_.deleted ItemCount} },
@{N="TotalDeletedItemSize" ;E={$_.Tot alDeletedI temSize}},
@{N="sentItemsCount";E={$_ .sentItems Count}},
@{N="TotalSentItemsSize";E ={$_.Total SentItemsS ize}},
@{N="Database";E={$_.Datab ase}} |
Export-CSV -Path "E:\scripts\Mail-Rpt.csv" -NoTypeInformation
Get-MailboxStatistics -Server MAIL1|
Sort-Object -Property TotalItemSize -Descending |
Select-Object -property DisplayName,@{N="ItemCount ";E={$_.It emCount}},
@{N="TotalItemSize";E={$_. TotalItemS ize}},
@{N="deletedItemCount";E={ $_.deleted ItemCount} },
@{N="TotalDeletedItemSize" ;E={$_.Tot alDeletedI temSize}},
@{N="Database";E={$_.Datab ase}} |
Export-CSV -Path "E:\scripts\Mail-Rpt1.csv" -NoTypeInformation
send-mailmessage -to postmaster@mailcom -from internal-email@mail.com -subject "Weekly mailbox
size report" -smtpserver "smtp" -attachments "E:\scripts\Mail-Rpt.csv", "E:\script s
\Mail-Rpt1.csv"
The overall item count in the mailbox
The overall size in MB and/or GB of the mailbox
The overall item count in the Deleted Items folder
The overall size in MB and/or GB of the Deleted Items folder
The overall item count in the Sent Items folder
The overall size in MB and/or GB of the Sent Items folder
I have come up with the following script by cutting and pasting numerous different source codes. The Total and Deleted functions are working but, I cannot get the Sent items to function or generate any data. Additionally, Is there a way to combine results from both mail servers?
Any and all help would be greatly appreciated.
SCRIPT FOLLOWS:
Get-MailboxStatistics -Server MAIL|
Sort-Object -Property TotalItemSize -Descending |
Select-Object -property DisplayName,@{N="ItemCount
@{N="TotalItemSize";E={$_.
@{N="deletedItemCount";E={
@{N="TotalDeletedItemSize"
@{N="sentItemsCount";E={$_
@{N="TotalSentItemsSize";E
@{N="Database";E={$_.Datab
Export-CSV -Path "E:\scripts\Mail-Rpt.csv" -NoTypeInformation
Get-MailboxStatistics -Server MAIL1|
Sort-Object -Property TotalItemSize -Descending |
Select-Object -property DisplayName,@{N="ItemCount
@{N="TotalItemSize";E={$_.
@{N="deletedItemCount";E={
@{N="TotalDeletedItemSize"
@{N="Database";E={$_.Datab
Export-CSV -Path "E:\scripts\Mail-Rpt1.csv"
send-mailmessage -to postmaster@mailcom -from internal-email@mail.com -subject "Weekly mailbox
size report" -smtpserver "smtp" -attachments "E:\scripts\Mail-Rpt.csv",
\Mail-Rpt1.csv"
ASKER
No values populating for Sent Items. :(
Try with get-mailboxfolderstatistic s $_.DisplayName
"MAIL","MAIL1" | % {
Get-MailboxStatistics -Server $_ |
Sort-Object -Property TotalItemSize -Descending |
Select-Object -property ServerName,DisplayName,@{N="ItemCount";E={$_.ItemCount}},
@{N="TotalItemSize";E={$_.TotalItemSize.Value.ToMB()}},
@{N="deletedItemCount";E={$_.deletedItemCount}},
@{N="TotalDeletedItemSize";E={$_.TotalDeletedItemSize.Value.ToMB()}},
@{N="sentItemsCount";E={(get-mailboxfolderstatistics $_.DisplayName -FolderScope SentItems).ItemsInFolder}},
@{N="TotalSentItemsSize";E={(get-mailboxfolderstatistics $_.DisplayName -FolderScope SentItems).FolderSize.ToMB()}},
@{N="Database";E={$_.Database}}
} | Export-CSV -Path "E:\scripts\Mail-Rpt.csv" -NoTypeInformation
ASKER
That was progress, unfortunately, it seems as though it is only partially working as only about half of the mailboxes returned values for the Sent Items and Sent Items Size. Ideas?
Hmm.. Probably they have identical display names..
Replace $_.DisplayName with $_.LegacyDN which is unique..
Replace $_.DisplayName with $_.LegacyDN which is unique..
ASKER
No joy. Still the same mailboxes with no data.
Do you mean all send item details come as empty or some of the mailbox values are empty?
ASKER
Some of the data populates and some do not. See attached file
Mail-Rpt.csv
Mail-Rpt.csv
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I appreciate the time you are spending but unfortunately, they are still coming up with the blanks.
I had modified the code after posting.. can you copy paste the code and try again?
ASKER
DONE! Let me work with it in the morning. I need to be able to generate a scheduled task and have it emailed several times a week. If you could monitor this post tomorrow that would be great. I will assign the points to you as an accepted solution. Thank you very much.
ASKER
subsun was fantastic in working this issue. I couldn't have asked for more! I am thrilled with the results. Hopefully they will help me resolve my Exchange issues.
Thank you so much subsun!!!!!
Thank you so much subsun!!!!!
ASKER
Is there a possibly a way to have this sort on the Deleted Items Size?
You can change it in line 4..
Sort-Object -Property TotalDeletedItemSize -Descending |
Sort-Object -Property TotalDeletedItemSize -Descending |
ASKER
Unfortunately.......No joy :( Now there is nothing sorted. I can manually sort but I would prefer to have it done when I open it.
~Schu
~Schu
Sorry my bad... Try this..
"MAIL","MAIL1" | % {
Foreach ($Mailbox in (Get-Mailbox -Server $_ -ResultSize Unlimited)) {
Get-MailboxStatistics $Mailbox |
Select-Object -property ServerName,DisplayName,@{N="ItemCount";E={$_.ItemCount}},
@{N="TotalItemSize";E={$_.TotalItemSize.Value.ToMB()}},
@{N="deletedItemCount";E={$_.deletedItemCount}},
@{N="TotalDeletedItemSize";E={$_.TotalDeletedItemSize.Value.ToMB()}},
@{N="sentItemsCount";E={(get-mailboxfolderstatistics $Mailbox.Alias -FolderScope SentItems |?{$_.folderpath -eq '/Sent Items'}).ItemsInFolder}},
@{N="TotalSentItemsSize";E={(get-mailboxfolderstatistics $Mailbox.Alias -FolderScope SentItems |?{$_.folderpath -eq '/Sent Items'}).FolderSize.ToMB()}},
@{N="Database";E={$_.Database}}
}
} | Sort-Object -Property TotalDeletedItemSize -Descending | Export-CSV -Path "E:\scripts\Mail-Rpt.csv" -NoTypeInformation
ASKER
It's all about placement! BadaBing! BadaBoom! Exactly what I was looking for!
Thank you Again!
~Schu
Thank you Again!
~Schu
Try..
Open in new window