我想执行ExchangeOnline命令,并通过 Select 某些属性将其转换为JSON,所有这些都在单个命令中完成!
例如,我的命令要 for each SharedMailbox
获取RecipientPermissions
,其输出为:
// command
Get-EXOMailbox -RecipientTypeDetails "SharedMailbox" -ResultSize unlimited | foreach { Get-EXORecipientPermission -Identity $_.Identity }
上述命令样例输出为
Identity : testexosv
Trustee : NT AUTHORITY\SELF
AccessControlType : Allow
AccessRights : {SendAs}
IsInherited : False
InheritanceType : All
Identity : SMBP
Trustee : 2b33e774737b4da26c2e551c00f
AccessControlType : Allow
AccessRights : {SendAs}
IsInherited : False
InheritanceType : None
首先,我想将上述输出转换为JSON.因此,如果我简单地将其传递到ConvertTo-Json
,则AccessRights
的值将丢失如下:
[
{
"Identity": "SMBP",
"Trustee": "2b33e774737b4da26c2e551c00f",
"AccessControlType": "Allow",
"AccessRights": [
1
],
"IsInherited": false,
"InheritanceType": "None"
},
{
"Identity": "testexosv",
"Trustee": "NT AUTHORITY\\SELF",
"AccessControlType": "Allow",
"AccessRights": [
1
],
"IsInherited": false,
"InheritanceType": "All"
}
]
其次,我只想在结果中 Select 特定的属性,例如:Identity, Trustee, AccessRights
,将它们重命名为任意键,并且仍然保持Json struct .所以我实际上想要的O/P是:
[
{
"ShareMailbox": "SMBP",
"UPN": "2b33e774737b4da26c2e551c00f",
"Roles": [
"SendAs"
]
},
{
"SharedMailbox": "testexosv",
"UPN": "NT AUTHORITY\\SELF",
"Roles": [
"SendAs"
]
}
]
我试过以下命令:
Get-EXOMailbox -RecipientTypeDetails "SharedMailbox" -ResultSize unlimited
| foreach { Get-EXORecipientPermission -Identity $_.Identity
| foreach {$_.Identity, $_.Trustee, [String]$_.AccessRights } | ConvertTo-Json}
但它只提供JSON数组,而不是JSON对象.上述命令的输出为
[
"SMBP",
"2b33e774737b4da26c2e551c00f",
"SendAs"
]
[
"testexosv",
"NT AUTHORITY\\SELF",
"SendAs"
]