Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Exchange 2010 Script

Posted on 2013-06-06
18
Medium Priority
?
340 Views
Last Modified: 2013-06-07
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={$_.ItemCount}},
                  @{N="TotalItemSize";E={$_.TotalItemSize}},
                  @{N="deletedItemCount";E={$_.deletedItemCount}},
                  @{N="TotalDeletedItemSize";E={$_.TotalDeletedItemSize}},
                  @{N="sentItemsCount";E={$_.sentItemsCount}},
                  @{N="TotalSentItemsSize";E={$_.TotalSentItemsSize}},
                  @{N="Database";E={$_.Database}} |
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={$_.ItemCount}},
                  @{N="TotalItemSize";E={$_.TotalItemSize}},
                  @{N="deletedItemCount";E={$_.deletedItemCount}},
                  @{N="TotalDeletedItemSize";E={$_.TotalDeletedItemSize}},
                  @{N="Database";E={$_.Database}} |
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:\scripts

\Mail-Rpt1.csv"
0
Comment
Question by:RFEMHelpdesk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 8
18 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 39226623
Get-mailboxstatistics does not return SentItems folder details. You need to use Get-mailboxfolderstatistics for that..

Try..
"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 -FolderScope SentItems).ItemsInFolder}},
                  @{N="TotalSentItemsSize";E={($_ | get-mailboxfolderstatistics -FolderScope SentItems).FolderSize.ToMB()}},
                  @{N="Database";E={$_.Database}}
} | Export-CSV -Path "E:\scripts\Mail-Rpt.csv" -NoTypeInformation

Open in new window

0
 

Author Comment

by:RFEMHelpdesk
ID: 39226659
No values populating for Sent Items. :(
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39227492
Try with get-mailboxfolderstatistics $_.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

Open in new window

0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:RFEMHelpdesk
ID: 39227649
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?
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39227661
Hmm.. Probably they have identical display names..
Replace $_.DisplayName with $_.LegacyDN which is unique..
0
 

Author Comment

by:RFEMHelpdesk
ID: 39227672
No joy. Still the same mailboxes with no data.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39227691
Do you mean all send item details come as empty or some of the mailbox values are empty?
0
 

Author Comment

by:RFEMHelpdesk
ID: 39227698
Some of the data populates and some do not. See attached file
Mail-Rpt.csv
0
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 total points
ID: 39227726
Ok..I have modified the code a bit.. Try now..
"MAIL","MAIL1" | % {
Foreach ($Mailbox in (Get-Mailbox -Server $_ -ResultSize Unlimited)) {
Get-MailboxStatistics $Mailbox |
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 $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}}
	}
} | Export-CSV -Path "E:\scripts\Mail-Rpt.csv" -NoTypeInformation

Open in new window

0
 

Author Comment

by:RFEMHelpdesk
ID: 39227750
I appreciate the time you are spending but unfortunately, they are still coming up with the blanks.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39227752
I had modified the code after posting.. can you copy paste the code and try again?
0
 

Author Comment

by:RFEMHelpdesk
ID: 39227764
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.
0
 

Author Closing Comment

by:RFEMHelpdesk
ID: 39227793
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!!!!!
0
 

Author Comment

by:RFEMHelpdesk
ID: 39229348
Is there a possibly a  way to have this sort on the Deleted Items Size?
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39229540
You can change it in line 4..

Sort-Object -Property TotalDeletedItemSize -Descending |
0
 

Author Comment

by:RFEMHelpdesk
ID: 39229638
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
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39229657
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

Open in new window

0
 

Author Comment

by:RFEMHelpdesk
ID: 39229685
It's all about placement! BadaBing! BadaBoom! Exactly what I was looking for!

Thank you Again!
~Schu
0

Featured Post

Are You Ready for GDPR?

With the GDPR deadline set for May 25, 2018, many organizations are ill-prepared due to uncertainty about the criteria for compliance. According to a recent WatchGuard survey, a staggering 37% of respondents don't even know if their organization needs to comply with GDPR. Do you?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question