首页 > 解决方案 > Exchange 导出脚本未写入单个 pst 文件

问题描述

我正在尝试使用以下脚本从 Exchange 导出禁用的用户邮箱,名称以“a”开头。如果我在没有管道或使用 -whatif 的情况下运行它,一切都很好,如果我运行它,批处理作业会尝试写入同一个 .pst 文件。

我当然不是 Powershell 专家,所以也许我遗漏了一些明显的东西。

Get-Mailbox -filter "recipienttype -eq 'usermailbox' -and exchangeuseraccountcontrol -eq 'accountdisabled' -and name -like 'a*'" | new-mailboxexportrequest -file path ("\\server\share\exportfolder\$_.pst")

干杯

标签: powershellexchange-server

解决方案


您可以使用以下方法实现您的目标:

Get-Mailbox -filter "recipienttype -eq 'usermailbox' -and exchangeuseraccountcontrol -eq 'accountdisabled' -and name -like 'a*'" `
| ForEach-Object `
{ new-mailboxexportrequest -Mailbox $_.Identity -filepath ("\\server\share\exportfolder\$($_.UserPrincipalName).pst") }

(添加换行符以提高可读性)

解释:

在您的代码中,您$_在此示例中使用的是邮箱对象数组。但是,参数的new-mailboxexportrequest预期String-FilePath。这就是为什么$($_.UserPrincipalName)需要。

添加了第一个美元符号和括号,以便您可以访问双引号之间的属性值。

最后,遍历所有可以使用的数组元素ForEach-Object(或者只是%它的别名)。


推荐阅读