Solved

How do I output Exchange mailboxStatistics to CSV file?

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A procedure for exporting installed hotfix details of remote computers using powershell
In this video we show how to create a Shared Mailbox 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 Recipients >> Sha…
This video discusses moving either the default database or any database to a new volume.

746 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

13 Experts available now in Live!

Get 1:1 Help Now