Quantcast
Channel: Exchange Server 2010 forum
Viewing all articles
Browse latest Browse all 8820

New-MailboxExportRequest PowerShell Script - ContentFilter behaving strangely

$
0
0

Hello,

I am having trouble with a PowerShell script that I have made for exporting a mailbox.

 

function userInput {
    $user = Read-Host "Enter the username you wish to archive"
    $start = Read-Host "Enter the date that you wish to archive from"
    $end = Read-Host "Enter the date that you wish to archive to"
    archiveMail $user $start $end
}
function archiveMail($userName, $startDate, $endDate) {
    if((($startDate -as [DateTime]) -ne $null) -and (($endDate -as [DateTime]) -ne $null)) {
    $startDate = [DateTime]::Parse($startDate)
    $endDate = [DateTime]::Parse($endDate)
    }
    else {
    Write-Host "a valid date was not given."
    userInput
    }
    if($userName -ne "") {
    New-MailboxExportRequest -BatchName $userName  -Mailbox $userName -FilePath "\\server\c$\temp\$userName.pst" -ExcludeFolders "#Calendar#","#Contacts#" -ExcludeDumpster -ContentFilter {((Received -le $endDate) -and (Received -ge $startDate)) -or ((Sent -le $endDate -and) (Sent -ge $startDate))}
    do {Write-Host -nonewline "."; Start-Sleep -s 10 } while(Get-MailboxExportRequest -BatchName $userName | Where {$_.Status -eq "Queued" -or $_.Status -eq "InProgress"})
    Write-Host ""
    Write-Host "Finished exporting"
    Get-MailboxExportRequest -BatchName $userName
    Write-Host "Writing Report"
    $completed = Get-MailboxExportRequest -BatchName $userName | Where {$_.Status -eq "Completed"} | Get-MailboxExportRequestStatistics | Format-List
    if($completed) {
    $completed | Out-File -FilePath "\\server\c$\temp\exportreports\$userName Completed.txt"
    }
    $incomplete = Get-MailboxExportRequest -BatchName $userName | Where {$_.Status -ne "Completed"} | Get-MailboxExportRequestStatistics | Format-List
    if($incomplete) {
    $incomplete | Out-File -FilePath "\\server\c$\temp\exportreports\$userName Incomplete.txt"
    }
    Write-Host "Removing Requests"
    Get-MailboxExportRequest -BatchName $userName | Remove-MailboxExportRequest -Confirm:$false    
    archiveMore
    }
    else {
    Write-Host "please enter a name"
    userInput
    }
}
function archiveMore {

    $cont = Read-Host "Would you like to archive another mailbox (Y/N)?"

    if($cont -eq "Y" -or $cont -eq "y") {
        userInput
    }
    else {
        if($cont -eq "N" -or $cont -eq "n") {
            Write-Host "Press any key to continue..."
            $finished = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
        }
        else {
            Write-Host "Invalid input given"
            archiveMore
        }
    }
}

userInput

After entering the username and the date range to add into the ContentFilter it starts the export fine. However it seems to go ahead and export the entire mailbox and not just the date range specified. After taking a look at the report given at the end, I noticed that the command is being changed somehow. See report below:

RunspaceId                    : 42c44b32-5bd1-4d18-b0f3-eb14ed47c845
Name                          : MailboxExport
Status                        : Completed
StatusDetail                  : Completed
SyncStage                     : SyncFinished
Flags                         : IntraOrg, Push
RequestStyle                  : IntraOrg
Direction                     : Push
Protect                       : False
Suspend                       : False
FilePath                      :
SourceAlias                   : user
SourceIsArchive               : False
SourceExchangeGuid            : 5a401df7-85b9-466e-b48a-47325b8ae490
SourceRootFolder              :
SourceVersion                 : Version 14.1 (Build 438.0)
SourceMailboxIdentity         : domain.local/OU/Domain Users/user
SourceDatabase                : Mailbox Database
TargetRootFolder              :
TargetVersion                 : Version 0.0 (Build 0.0)
IncludeFolders                : {}
ExcludeFolders                : {#Calendar#, #Contacts#}
ExcludeDumpster               : True
ConflictResolutionOption      : KeepSourceItem
AssociatedMessagesCopyOption  : DoNotCopy
BatchName                     : user
ContentFilter                 : ((((Received -ne $null) -and (Received -ne $null))) -or (((Sent -ne $null) -and (Sent -
                                ne $null))))
ContentFilterLanguage         :
BadItemLimit                  : 0
BadItemsEncountered           : 0
QueuedTimestamp               : 8/05/2013 4:51:16 PM
StartTimestamp                : 8/05/2013 4:51:19 PM
LastUpdateTimestamp           : 8/05/2013 4:54:56 PM
CompletionTimestamp           : 8/05/2013 4:54:55 PM
SuspendedTimestamp            :
OverallDuration               : 00:03:39
TotalSuspendedDuration        :
TotalFailedDuration           :
TotalQueuedDuration           : 00:00:02
TotalInProgressDuration       : 00:03:36
TotalStalledDueToHADuration   :
TotalTransientFailureDuration :
MRSServerName                 : server.domain.local
EstimatedTransferSize         : 277.9 MB (291,408,690 bytes)
EstimatedTransferItemCount    : 3631
BytesTransferred              : 299.5 MB (314,041,625 bytes)
BytesTransferredPerMinute     :
ItemsTransferred              : 3609
PercentComplete               : 100
PositionInQueue               :
FailureCode                   :
FailureType                   :
FailureSide                   :
Message                       :
FailureTimestamp              :
FailureContext                :
IsValid                       : True
ValidationMessage             :
OrganizationId                :
RequestGuid                   : 1a88d6ab-b35c-49cb-a7bc-1cc591c4459b
RequestQueue                  : Mailbox Database
Identity                      : RequestGuid (1a88d6ab-b35c-49cb-a7bc-1cc591c4459b), RequestQueue: (6b9b567d-e8d8-43f5-a
                                84f-0ba99e0975e1)
Report                        :

For some reason the Exchange server or PowerShell changes the semantics of the ContentFilter. Can anyone help?

 

Viewing all articles
Browse latest Browse all 8820

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>