Solved

How do I output Exchange mailboxStatistics to CSV file?

Posted on 2011-09-28
2
875 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
[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
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

726 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