Link to home
Start Free TrialLog in
Avatar of TigerBlood
TigerBlood

asked on

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



 
Avatar of TigerBlood
TigerBlood

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of soostibi
soostibi
Flag of Hungary image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
(Sorry, you can delete line 13, it was just for placing a breakpoint during testing)
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:

https://www.experts-exchange.com/questions/27182854/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.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?