Solved

How do I output Exchange mailboxStatistics to CSV file?

Posted on 2011-09-28
2
849 Views
Last Modified: 2012-05-12
I have the following script, which generates a report on exchange mailboxes and I want it to output values for all the fields listed in the "Select-Object" section at the end of the script.  Only the DisplayName, SMTP Address, Retention Policy, NewestItem, and OldesItem are being output.  I am trying to get it to output a value for Total Items, NewestItemFolder and OldestItemFolder.  What changes do I need to make to my script for this to work?

Also, with the script in it's current state are other folders/ sub-folders in the mailbox that are created by the user with the intent for holding emails scanned? If now, how would I add that to the script?

The script should only scan the Inbox, Sent Items and any user created folder used for storing emails.  I do not wish to scan Calendars, Tasks, Notes or Contacts in my script.  

 
$mbxs = Get-Mailbox 
$typestoinclude = "Inbox", “SentItems”
$recurse = $true

filter get-folders ($roottypes, [switch] $recurse){
$mb = $_
$roottypes | %{
$type = $_
$root = $mb | Get-MailboxFolderStatistics -FolderScope $type -IncludeOldestAndNewestItems |?{$_.foldertype -eq $type} 
if($recurse){
    $mb | get-mailboxfolderstatistics -IncludeOldestAndNewestItems |  ?{$_.folderpath -match "^$($root.folderpath)"} 
}
else {$root}
}
}

$mbxs | %{
    $newest = $oldest = $null
    $mb = $_
    $mb | Get-folders $typestoinclude -recurse:$recurse | %{
        if($_.NewestItemReceivedDate -and (!$newest -or $newest -lt $_.NewestItemReceivedDate.tolocaltime())){
            $newest = $_.NewestItemReceivedDate.tolocaltime()}
        if($_.OldestItemReceivedDate -and (!$oldest -or $oldest -gt $_.OldestItemReceivedDate.tolocaltime())){
                $oldest = $_.OldestItemReceivedDate.tolocaltime()}
    }
    $stat = $mb | Get-MailboxStatistics
        New-Object -TypeName psobject -Property @{  
            DisplayName = $mb.displayname  
            SMTPAddress = $mb.PrimarySMTPAddress.tostring()  
            RetentionPolicy = $mb.retentionpolicy  
            ItemsInMailbox = $stat.ItemCount
            NewestItem = $newest
            NewestItemFolder = $newestrow.name
            OldestItem = $oldest
            OldestItemFolder = $oldestrow.name
        }
} | Select-Object -Property displayName, SMTPAddress, RetentionPolicy, TotalItems, NewestItem, NewestItemFolder, OldestItem, OldestItemFolder | Export-Csv C:\output.csv –NoTypeInformation

Open in new window

0
Comment
Question by:TigerBlood
2 Comments
 
LVL 32

Accepted Solution

by:
endital1097 earned 500 total points
ID: 37021740
you need to update the get-mailboxfolderstatistics to reflect something like the following
Get-MailboxFolderStatistics | Where { $_.FolderScope -ne "Calendar" -Or $_.FolderScope -ne "Contacts" }

Add the other scopes you wish to exclude
There is no format that will collect statistics for folders that contain items of type




0
 

Author Comment

by:TigerBlood
ID: 37047852
Thanks for your response, Endital1097.  Just looking into this.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
Find out what you should include to make the best professional email signature for your organization.
In this video we show how to create an Address List in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Organization >> Ad…
To show how to generate a certificate request in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Servers >> Certificates…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now