title: Automating Exchange Mail Box Export using Task Scheduler and Powershell
body: <p>i'm trying to regularly export PST files from user mail boxes in MS Exchange v14.1 (build 218.15) as an alternative means of Backing up. I'm running on Windows SBS 2011.</p>
  
  <p>I have a powershell script that looks like this...</p>
  
  <pre><code>Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
  . $env:ExchangeInstallPath\bin\RemoteExchange.ps1
  Connect-ExchangeServer -auto
  
  $lastweek = (get-date).AddDays(-7)
  $date1 = $lastweek.ToString("dd/MM/yyyy")
  $date2 = (get-date).ToString("dd.MM.yyyy")
  $path = "\\master\PSTFiles\"+$date2+"\"
  New-Item -Path $path -type directory | Out-Null
  
  New-MailboxExportRequest -ContentFilter "Received -gt'$date1'" -ExcludeFolders "#DeletedItems#" -Mailbox myusername -FilePath $path"myusername.pst"
  </code></pre>
  
  <p>I then call this script using Task Scheduler with a set up like this...</p>
  
  <pre><code>Start Program: C:\windows\system32\windowspowershell\v1.0\powershell.exe
  Arguments: .\my-exchange-export-script.ps1
  Start in: C:\BackupScript
  </code></pre>
  
  <p>which is set up to run using a domain user account, whether logged in or not and with Run with highest privileges set. This user account has domain administrator permissions on the Server and the Exchange "Import / Export" Role under RBAC.</p>
  
  <p>Additionally i've also "Set-ExecutionPolicy Unrestricted -force" for this user account and in desperation i've also turned off UAC settings for the Server too.</p>
  
  <p>The script runs fine if i just right click it and "run with Powershell", 
  however when triggered by the Task Scheduler starts but only gets as far as creating the new directory, and then doesn't do anything else. </p>
  
  <p>Has anyone any useful suggestions as to what might be stopping my request and what i could do to make it work? </p>
  
  <p>Cheers
  phil</p>