Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

Exchange Archiving Script

$
0
0

Hello!

New problem to write a script for now! - We have a Journaling mailbox that needs to be exported to a PST and cleared out - That bit is fairly simple;

$date1 = get-date
$date = $date1.AddMonths(-9)
$quarter = $date.AddMonths(-12)
$year = $date.year

$ref = Get-Content "C:\Scripts\ref.txt"

$archive = "$year"+" $ref"+"1"

$dir = New-Item -ItemType Directory "\\SERVER\JournalingBackup\$archive" -Force
$file = New-Item -ItemType File "$dir\Journal Archive.pst" -Force


New-MailboxExportRequest -ContentFilter { (Received -le $date) -and (Received -ge $quarter) } -Mailbox "JMailbox" -FilePath "$dir\Journal Archive.pst" 
Write-Host "`n Press any Key Exit..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

(Just to clarify, this is run through task scheduler which I have pre-configured to run the script in EMS)

Nice and Simple! (but not finished)

But. I am trying to save it to a "Local Disk" (ISCSI). Every time the script runs for the first time (i.e. creates a new folder) it generates this error:

Unable to open PST file '\\SERVER\JournalingBackup\2012 11\Journal Archive.pst'. Error details: Data read at file offset
 0 is 0 bytes. It should have been 576 bytes
    + CategoryInfo          : NotSpecified: (0:Int32) [New-MailboxExportRequest], RemotePermanentException
    + FullyQualifiedErrorId : 21F7D836,Microsoft.Exchange.Management.RecipientTasks.NewMailboxExportRequest

No idea what to make of it. From this point forth, sometimes it is not possible to delete the file that was created because it is "In Use by the System Process" or it will fail to recreate the file and start the archiving. Sometimes when this happens, the file is visible in explorer but Test-Path returns "False". The only way around it is kill the ISCSI service and restart it, delete the file and attempt to run it again. I did try to run the script without the $file variable in case the EMS created the file, but it says the file does not exist.

Now I could spend a little time and write a script that troubleshoots and uses work around, but I'd rather find the problem than cover it up. Any ideas?

Regards,

Bertand1


Bertand1 Answered your Question? - Mark it as the Answer Been helpful rather than hindering? - Mark it as helpful!


Viewing all articles
Browse latest Browse all 2562

Trending Articles



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