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

An iteration to the question: How do I omit specific mailbox folders from being searched in PowerShell when running a script to pull mailbox and mailbox folder information?

I have another iteration I am trying to complete for the question I posted on 4/25/2011 (Question Title: How do I omit specific mailbox folders from being searched in PowerShell when running a script to pull mailbox and mailbox folder information?)

I would still like to keep the mailbox seach restricted to Inbox, SentItems and UserCreated.  The change I am looking to make would be to what is outputted to the csv file and keeping the info per mailbox to one line only.

Can we have one 1 line per user still catching the same info (not including the folder type column)?  The csv output file should look like this:

displayName, SMTPAddress, RetentionPolicy, ItemsInMailbox, NewestItem, NewestItemFolder, OldestItem, OldestItemFolder



 
0
TigerBlood
Asked:
TigerBlood
  • 2
  • 2
1 Solution
 
TigerBloodAuthor Commented:
Below is the script for refernence, which I am looking to have updated.  Thanks!
 
$mbxs = Get-Mailbox 
$types = "Inbox", "SentItems", "User Created"
$mbxs | %{  
    $newest = $oldest = $null  
    $newestrow = $oldestrow = $null
    $mb = $_  
    $mb | Get-MailboxFolderStatistics -IncludeOldestAndNewestItems | ?{$types -contains $_.foldertype} |%{  
        if($_.NewestItemReceivedDate -and (!$newest -or $newest -lt $_.NewestItemReceivedDate.tolocaltime())){  
            $newest = $_.NewestItemReceivedDate.tolocaltime()
            $newestrow = $_ 
        }  
        $dummy = 1
        if($_.OldestItemReceivedDate -and (!$oldest -or $oldest -gt $_.OldestItemReceivedDate.tolocaltime())){  
            $oldest = $_.OldestItemReceivedDate.tolocaltime()
            $oldestrow = $_ 
        }
    }  
    if($newestrow -and $oldestrow -and $newestrow.identity.tostring() -eq  $oldestrow.identity.tostring()){
        New-Object -TypeName psobject -Property @{  
            DisplayName = $mb.displayname  
            SMTPAddress = $mb.PrimarySMTPAddress.tostring()  
            RetentionPolicy = $mb.retentionpolicy  
            FolderName = $newestrow.name
            ItemsInFolder = $newestrow.itemsinfolder
            NewestItem = $newest
            OldestItem = $oldest
            FolderType = $newestrow.foldertype
        }      
    }
    else{
        if($newestrow){
            New-Object -TypeName psobject -Property @{  
                DisplayName = $mb.displayname  
                SMTPAddress = $mb.PrimarySMTPAddress.tostring()  
                RetentionPolicy = $mb.retentionpolicy  
                FolderName = $newestrow.name
                ItemsInFolder = $newestrow.itemsinfolder
                NewestItem = $newest
                OldestItem = $null
                FolderType = $newestrow.foldertype
            }
        }
        if($oldestrow){      
            New-Object -TypeName psobject -Property @{  
                DisplayName = $mb.displayname  
                SMTPAddress = $mb.PrimarySMTPAddress.tostring()  
                RetentionPolicy = $mb.retentionpolicy  
                FolderName = $oldestrow.name
                ItemsInFolder = $oldestrow.itemsinfolder
                NewestItem = $null
                OldestItem = $oldest
                FolderType = $oldestrow.foldertype
            }      
        }
    }
} | Select-Object -Property DisplayName, SMTPAddress, RetentionPolicy, FolderName, ItemsInFolder, NewestItem, OldestItem, FolderType  |   
    Export-Csv C:\Output.csv –NoTypeInformation

Open in new window

0
 
soostibiCommented:
Here you are:
$mbxs = Get-Mailbox 
$types = "Inbox", "SentItems", "User Created"
$mbxs | %{  
    $newest = $oldest = $null  
    $newestrow = $oldestrow = $null
    $mb = $_  
    $mbstat = Get-MailboxStatistics -Identity $mb
    $mb | Get-MailboxFolderStatistics -IncludeOldestAndNewestItems | ?{$types -contains $_.foldertype} |%{  
        if($_.NewestItemReceivedDate -and (!$newest -or $newest -lt $_.NewestItemReceivedDate.tolocaltime())){  
            $newest = $_.NewestItemReceivedDate.tolocaltime()
            $newestrow = $_ 
        }  
        $dummy = 1
        if($_.OldestItemReceivedDate -and (!$oldest -or $oldest -gt $_.OldestItemReceivedDate.tolocaltime())){  
            $oldest = $_.OldestItemReceivedDate.tolocaltime()
            $oldestrow = $_ 
        }
    }  
        New-Object -TypeName psobject -Property @{  
            DisplayName = $mb.displayname  
            SMTPAddress = $mb.PrimarySMTPAddress.tostring()  
            RetentionPolicy = $mb.retentionpolicy  
            ItemsInMailbox = $mbstat.ItemCount
            NewestItem = $newest
            NewestItemFolder = $newestrow.name
            OldestItem = $oldest
            OldestItemFolder = $oldestrow.name
        }
} | Select-Object -Property displayName, SMTPAddress, RetentionPolicy, ItemsInMailbox, NewestItem, NewestItemFolder, OldestItem, OldestItemFolder |   
        ft

Open in new window

0
 
soostibiCommented:
(Sorry, you can delete line 13, it was just for placing a breakpoint during testing)
0
 
TigerBloodAuthor Commented:
Hi Soostibi - I have an additional question relating to the script solution you gave above.  As this question was closed I created a new question string here:

http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_27182854.html

Question title:
What is the Exchange 2010 mail item "field name" where the value for a retention tag is held and how do I call on this value in Powershell?
0

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

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