In previous versions of ARS v6.x I've been able run the following script to export an Exchange mailbox to a .pst file as part of a deprovisioning policy:
function onDeprovision($Request) {
# Check target object class
if ($Request.Class -ne "user") { return; }
# Get user information
$userLogon = $dirObj.Get("sAMAccountName")
if (($userLogon -eq $null) -or ($userLogon -eq "")) { return; }
$userSMTP = $dirObj.Get("mail")
if (($userSMTP -eq $null) -or ($userSMTP -eq "")) { return; }
$userGN = $dirObj.Get("givenName")
if (($userGN -eq $null) -or ($userGN -eq "")) { return; }
$userSN = $dirObj.Get("sn")
if (($userSN -eq $null) -or ($userSN -eq "")) { return; }
$dstPath = "\\myfileserver.acme.com\Deprovisioned-Users" + "\" + $userGN + "." + $userSN
$fileName = $userLogon + "_mbox.pst"
$jobName = $userLogon + "_mbox-export"
# Perform path testing
if (Test-Path -Path "$dstPath\$fileName") { return }
if (-not (Test-Path -Path $dstPath)) { New-Item -Path $dstPath -ItemType Directory -Force -Confirm:$false }
# Add PowerShell snapin for Exchange 2010 management
Add-PSSnapin -Name "Microsoft.Exchange.Management.PowerShell.E2010" -ErrorAction SilentlyContinue
# Submit Exchange Mailbox Export Request
New-MailboxExportRequest -Mailbox $userSMTP -FilePath "$dstPath\$fileName" -Name $jobName
} # End function onDeprovision
This process does not work in ARS v7.x which results in the following error:
Administrative Policy returned error. At line: 18 char:5. Exception calling "Get" with "1" argument(s): "The directory property cannot be found in the cache."
The error seems pretty explicit but for some reason I haven't been able to get this to work. I'm obviously doing something (or many things) wrong, any recommendations?
Secondary question: Does it make more sense to use a workflow for this?