Question

I am trying to dump a user's PST file and Delete the contents using Exchange 2013.

I understand these 2 processes and have no problem executing this.

To Dump the pst I create a New-MailboxExportRequest and to delete the items I do a Search-Mailbox ... -DeleteContent. This is all no problem.

The issue I am having is that these 2 commands are bundled into one .ps1 file. This file is scheduled to run daily.

Sometimes the MailboxExportRequest takes abnormally long to queue and execute (sometimes 15-20 minutes). My fear is that having these 2 scripts bundled together, the delete is going to execute before my dump starts.

How do I prevent this from happening?

Was it helpful?

Solution

So, New-MailboxExportRequest generates a MailboxExportRequest object if I remember my Exchange 2010 class right. Couldn't you store that in a variable, and then start a while loop that sleeps for 30 seconds until the job is done? Something like:

$MailExport = New-MailboxExportRequest -FilePath <path> -Mailbox SomeGuysMailboxID
While(!(Get-MailboxExportRequest -Id $MailExport).Status -eq "Complete"){Start-Sleep -S 30}
Search-Mailbox ... -DeleteContent

Or if it doesn't return an object you can specify a name for it I'm pretty sure, and then get the status by job name. Either way you can just check the status and put in a sleep command to make the script wait until the job is done before moving on.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top