【问题标题】:Automating Exchange Mail Box Export using Task Scheduler and Powershell使用任务计划程序和 Powershell 自动导出 Exchange 邮箱
【发布时间】:2013-12-22 10:33:01
【问题描述】:

我正在尝试定期从 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 运行”,脚本运行良好, 但是,当由任务计划程序触发时,启动但仅会创建新目录,然后不执行任何其他操作。

关于什么可能会阻止我的请求以及我可以做些什么来使它起作用,有没有人有任何有用的建议?

干杯 菲尔

【问题讨论】:

  • 您不需要加载该管理单元。只需连接到 Exchange 会话,并在导出请求上使用 Invoke-Command,指向该会话。

标签: powershell automation scheduled-tasks exchange-server


【解决方案1】:

好的,我已经修复了它,但我不确定我尝试过的许多事情中哪一个能完成这项工作。

我已将安全权限“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" 

这运行成功了!

可能我采取的一些步骤和我设置的权限对于任务来说是多余的,但我懒得消除它们

希望这对其他人有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-01
    • 1970-01-01
    • 2021-09-16
    • 2018-04-14
    • 2014-08-17
    • 2014-12-28
    • 2014-02-28
    相关资源
    最近更新 更多