我正在尝试定期从MS Exchange v14.1(版本218.15)中的用户邮箱导出PST文件,作为备份的替代方法。我在Windows SBS 2011上运行。
我有一个看起来像这样的powershell脚本......
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"
然后我使用任务计划程序调用此脚本,其设置如下...
Start Program: C:\windows\system32\windowspowershell\v1.0\powershell.exe
Arguments: .\my-exchange-export-script.ps1
Start in: C:\BackupScript
设置为使用域用户帐户运行,无论是否已登录,并且设置了具有最高权限的“运行”。此用户帐户在服务器上具有域管理员权限,在RBAC下具有Exchange“导入/导出”角色。
此外,我还为此用户帐户设置了“Set-ExecutionPolicy Unrestricted -force”,在绝望中我也关闭了服务器的UAC设置。
如果我右键单击它并“使用Powershell运行”,脚本运行正常, 但是当由任务计划程序启动时,但只能创建新目录,然后不执行任何其他操作。
是否有任何有用的建议可能会阻止我的请求以及我可以做些什么来使其发挥作用?
干杯 菲尔
答案 0 :(得分:0)
好的我已经修好了,但我不确定我尝试过的很多东西都能完成这项工作。
我已将安全权限“WSS_ADMIN_WGP”添加到用户帐户,因为管理员角色已拥有该权限。
我已升级到Exchange 2010 SP3并为我的用户帐户提供了我能找到的每个Exchange角色。
我在调用脚本时添加了一个中间步骤,所以现在SCHEDULED TASK看起来像这样...
Start Program: C:\windows\system32\windowspowershell\v1.0\powershell.exe
Arguments: .\run-as-admin-script.ps1
Start in: C:\BackupScript
然后“run-as-admin-script.ps1”看起来像这样(这需要关闭UAC )
Start-Process "$psHome\powershell.exe" -verb runas -ArgumentList "-file C:\BackupScript\exchange-export-script-incremental.ps1"
“exchange-export-script-incremental.ps1”现在看起来像这样......
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
. $env:ExchangeInstallPath\bin\RemoteExchange.ps1
Connect-ExchangeServer -auto
$lastweek = (get-date).AddDays(-7)
$tomorrow = (get-date).AddDays(+1)
$date2 = (get-date).ToString("dd.MM.yyyy")
$path = "\\master\PSTFiles\"+$date2+"\"
New-Item -Path $path -type directory | Out-Null
New-MailboxExportRequest -ContentFilter {(Received -gt $lastweek) -and (Received -lt $tomorrow)} -Mailbox myusername -FilePath $path"myusername.pst"
这次成功运行!
我可能采取的一些步骤和我设置的权限对于任务来说是多余的,但我不能为消除它们而烦恼
希望这对其他人有用。