• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 892
  • Last Modified:

How do I output Exchange mailboxStatistics to CSV file?

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
TigerBlood
Asked:
TigerBlood
1 Solution
 
endital1097Commented:
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
 
TigerBloodAuthor Commented:
Thanks for your response, Endital1097.  Just looking into this.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now