Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Clear out old messages in Exchange 2010 journal mailbox after messages are archived to .PST Getting Error on Date

$
0
0


# THIS IS THE FIRST COMMAND THAT I RUN IN A SEPARATE .PS1 FILE. THIS SEEMS TO WORK FINE:
New-MailboxExportRequest JournalMailbox -FilePath '\\dfsdr.dc.pud\PowershellEmailArchive\Journal.pst'


# NEXT I AM TRYING TO CLEAN OUT EVERYTHING ELSE UP UNTIL 1-2 DAYS AGO BUT GETTING THIS ERROR:

[PS] C:\scripts>.\CleanOutOldMsg.ps1
Please adjust the date time. Make sure it is in the correct format.
    + CategoryInfo          : InvalidArgument: (:) [], ParserException
    + FullyQualifiedErrorId : 44F6D37F


# HERE'S WHAT I'VE DONE:
$global:startDate = (Get-Date).AddDays(-31).ToString('MM/dd/yyy')
$global:endDate = (get-date).AddDays(-1).ToString('MM/dd/yyy')

# HAVE TRIE THIS DATE FORMAT TOO:

$endDate = (Get-Date).AddDays(-1).ToShortDateString()
$startDate = (Get-Date).AddDays(-31).ToShortDateString()

# AND ALSO THIS DATE FORMAT:

# $endDate = Get-Date -Day 2 "00:00:00"
# $startDate = $endDate.AddDays(-30)

# $endDate = $endDate.ToShortDateString()
# $startDate = $startDate.ToShortDateString()


# THIS COMMAND GIVES DATE ERRORS:
Search-Mailbox -Identity JournalMailbox -TargetFolder inbox -TargetMailbox jimk -SearchQuery "Received:'${startDate}'..'${endDate}'" -DeleteContent -Force

# THIS COMMAND GIVES DATE ERRORS TOO:
Get-Mailbox -Identity "JournalMailbox" | Search-Mailbox -SearchQuery "Received:'${startDate}'..'${endDate}'" -DeleteContent -Force

# THIS WORKS:
Search-Mailbox -Identity JournalMailbox -TargetFolder inbox -TargetMailbox jimk -SearchQuery "Received:02/07/2014..03/07/2014" -DeleteContent -Force


# I FOUND SOME OF THE INFORMATION HERE:
# https://serverfault.com/questions/511610/how-can-i-move-exchange-items-to-a-pst-using-powershell


Thanks in advance! Jim

Viewing all articles
Browse latest Browse all 21975

Trending Articles



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