The script runs no problem only thing it does not clear the inbox data
These two lines of the code
search-mailbox -identity journalman -searchquery “$FilterS” -deletecontent -force | out-file $LogFolder$LogFile -append
search-mailbox -identity spamman -searchquery “$FilterS” -deletecontent -force | out-file $LogFolder$LogFile -append
The full script
$Server = hostname
$Subject = “$Server Export Journal\Spam”
$Body = “Open attachment for Export Journalman/Spamman Inboxes Weekly Report”
$From = “no-reply@mynet.com”
$To = “systems-alert@mynet.com”
$LogFolder = “c:\util\logs”
$LogFile = “journalman.txt”
$MRSLog1 = “MRS-History-Spamman.Log”
$MRSLog2 = “MRS-History-Journalman.Log”
$today = Get-Date -Format “MMddyyyy”
$Folder = “\10.12.18.23\PST\journalman-$today.pst”
$FolderS = “\10.12.18.23\PST\spamman-$today.pst”
$FolderM = "\10.12.18.13\usbshare1\PST"
$FolderX = “\10.12.18.23\PST”
$PSEmailServer = “InternalRelay.MYNET.COM”
remove-item -path $LogFolder$LogFile -Force
remove-item -path $LogFolder$MRSLog1 -Force
remove-item -path $LogFolder$MRSLog2 -Force
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::CreateSpecificCulture(“en-us”)
Add-PSSnapin microsoft.exchange.management.powershell.SnapIn;
$start = (get-date).adddays(-7).toString(‘MM/dd/yyyy’)
$end = (get-date).toString(‘MM/dd/yyyy’)
$filter = “(Received>=”+$start+“) and (Received<=”+$end+“)”
$filterE = “(Received -gt '”+$start+“') -and (Received -lt '”+$end+“')”
$filterS = “received<=”+$end+" and received>=“+$start+”"
Get-MailboxExportRequest | out-file $LogFolder$LogFile -append
Get-MailboxExportRequest -Status Completed | Remove-MailboxExportRequest -confirm:$false | out-file $LogFolder$LogFile -append
New-MailboxExportRequest –Mailbox Journalman -Name MyNextAttempt -FilePath $folder -ContentFilter “$filterE” -confirm:$false -verbose -baditemlimit 100 -AcceptLargeDataLoss | out-file $LogFolder$LogFile -append
New-MailboxExportRequest –Mailbox spamman -Name MyNextAttempt -FilePath $folderS -ContentFilter “$filterE” -confirm:$false -verbose -baditemlimit 100 -AcceptLargeDataLoss | out-file $LogFolder$LogFile -append
start-sleep -Seconds 300
Write-Output “Clearing Mailboxes Content Now” | out-file $LogFolder$LogFile -append
search-mailbox -identity journalman -searchquery “$FilterS” -deletecontent -force | out-file $LogFolder$LogFile -append
search-mailbox -identity spamman -searchquery “$FilterS” -deletecontent -force | out-file $LogFolder$LogFile -append
Get-MailboxExportRequest | Where {$.Status -eq “Completed”} | out-file $LogFolder$LogFile -append
Get-MailboxExportRequest | Where {$.Status -eq “Completed”} | Remove-MailboxExportRequest -confirm:$false | out-file $LogFolder$LogFile -append
Test-MRSHealth | out-file $logfolder$logfile -Append
$MoveHistory = Get-MailboxStatistics “spamman”
$MoveHistory[0] | Out-file –FilePath $logfolder$MRSlog1
$MoveHistory = (Get-MailboxStatistics “journalman” -IncludeMoveReport).movehistory
$MoveHistory[0] | Out-file –FilePath $logfolder$MRSlog2
move-item -path $folderx*.pst -destination $folderM | out-file $LogFolder$LogFile -append
get-childitem -Path $folderm -Recurse | out-file $LogFolder$LogFile -append
send-MailMessage -From $From -To $To -Subject $Subject -Body $Body -smtpserver $PSEmailServer -attachment “$LogFolder$LogFile”, “$logfolder$MRSlog1”, “$logfolder$MRSlog2”
Any ideas?
Thank you,
Tom