powershell - PowerShell 哈希表问题 - office 365
问题描述
我需要在 O365 中为大约 80 个用户设置 OOF 消息。
我找到了一个 cmdlet Set-MailboxAutoReplyConfiguration,我可以使用它来自动化该过程,它看起来不错,但我可能遗漏了一些东西。
这是代码:
$usersfile = import-csv "C:\Users\Out Of office bulk\Users.csv"
$setmailbox = @{
'Identity' = $usersfile.UserPrincipalName
'AutoReplyState' = 'Scheduled'
'externalaudience' = 'all'
'InternalMessage' = 'I am not here'
'ExternalMessage' = 'I am not here'
'StartTime' = '01/02/2020 01:00:00'
'EndTime' = '02/02/2020 23:00:00'
}
Set-MailboxAutoReplyConfiguration @setmailbox
我的问题是 Identity 参数,
当我运行 $setmailbox
我可以看到它从 csv 文件中显示了正确的 UPN:
Name Value
---- -----
AutoReplyState Scheduled
externalaudience all
Identity {blah@blah.com, blah2@blah.com}
StartTime 01/02/2020 01:00:00
EndTime 02/02/2020 23:00:00
InternalMessage I am not here
ExternalMessage I am not here
但是当我运行脚本时,我收到了这个错误:
Cannot process argument transformation on parameter 'Identity'. Cannot convert the "System.Collections.ArrayList" value of type "System.Collections.ArrayList" to type "Microsoft.Exchange.Configuration.Tasks.MailboxLocationIdParameter".
+ CategoryInfo : InvalidData: (:) [Set-MailboxAutoReplyConfiguration], ParameterBindin...mationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-MailboxAutoReplyConfiguration
+ PSComputerName : outlook.office365.com
我试图改变这一点:
'Identity' = $usersfile.UserPrincipalName
几乎任何事情,它没有工作。
非常感谢你的帮助。
PS:
我知道我可以做这样的事情:
Import-Csv 'C:\Users.csv' | ForEach-Object {
$user = $_."UserPrincipalName"
Set-MailboxAutoReplyConfiguration `
-Identity $user -AutoReplyState Scheduled -StartTime "07/10/2018 01:00:00" `
-EndTime "7/15/2018 23:00:00" -InternalMessage "I am not here" -ExternalMessage "I am not here."
}
但出于实践目的,我更喜欢使用哈希表来更好地理解它。
解决方案:感谢@Lee_Dailey,我没有注意到identity
参数每次只接受一个用户,所以多用户的解决方案是使用foreach-object
.
解决方案
推荐阅读
- unity3d - 根据世界空间中的光线投射命中位置绘制到对象的纹理上
- python - 如何将对象保存到 JSON 列表?
- animation - 通过在 Flutter 中将不透明度设置为 0 并返回 1 来更改 Text 小部件的值
- vba - Office 365 VBA编辑器查找窗口(CTRL+F)总是跳到双显示器之间的分界线
- amazon-web-services - 如何在 CloudFormation 模板中将数据从 AWS S3 复制到 EC2?
- c# - “new”关键字的 C# 别名
- authentication - 将gmail附加到我的非gmail帐户后,如何将登录过程修复到对话流?
- docker - 如何使用 Docker-Compose 从 Hashicorp Vault 存储和检索秘密?
- express - 快速定义路线混淆 app.use()
- xamarin - xamarin 共享项目中 xml 的规范化