powershell - 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")
干杯
解决方案
您可以使用以下方法实现您的目标:
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
(或者只是%
它的别名)。
推荐阅读
- python - 使用结构将浮点数从 Arduino 发送到 Python
- arrays - 使用 Push 和 Slice 更新 MongoDB 数组
- sql - 根据计数对记录集进行分类
- java - 在 64 位 JVM 上是读取和写入双原子吗?
- sql-server - 在所有数据库上查询 INFORMATION_SCHEMA.COLUMNS?
- javascript - CORS 阻止了我的后端服务器,如何解决?使用 Springboot java 作为后端, react js 作为我的前端
- sql - UNION ALL 未按预期执行 - Oracle SQL
- python - 在 Azure Functions 中导入 Google Cloud python 库时出错
- javascript - 当我尝试将其作为道具传递给其他组件时,获取响应返回未定义
- nosql - 是否使用 Kafka Streams 和/或 KSQL 对来自数据库的数据流进行非规范化处理