来自 CMD 的 运行 时出现 New-MailboxExportRequest 错误

New-MailboxExportRequest error when running from CMD

我有一个非常简单的 PowerShell 脚本,它 运行 是 new-mailboxexportrequest 命令。如果我 运行 将脚本作为计划任务,我会收到以下错误: new-mailboxexportrequest: 无法与邮箱数据库通信。 如果我打开 PowerShell 命令提示符和 运行 脚本,我会得到同样的错误。 该脚本仅在我手动打开 交换管理 shell 和 运行 脚本时有效。

请记住,脚本的第一行实际上有 exchange snapin 命令: 添加 pssnapin Microsoft.Exchange.Management.PowerShell.E2010

问题是,交换管理 shell 中的哪些负载在管理单元 运行 时没有加载?

此外,计划任务、手动电源shell命令和交换管理shell命令都运行在同一个盒子(交换服务器)上。我也 运行 使用相同的用户帐户将它们连接起来。

感谢任何帮助。

您的问题的原因在 link:

中有解释

https://blogs.technet.microsoft.com/rmilne/2015/01/28/directly-loading-exchange-2010-or-2013-snapin-is-not-supported/

这应该可以解决您的问题:

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://<ServerFQDN>/PowerShell/ -Authentication Kerberos
Import-PSSession $Session

你也可以检查这个:

powershell -psconsolefile "C:\Program Files\Microsoft\Exchange Server\Bin\exshell.psc1" your-exchange-command