我想通过从结果中排除一些访问权限来获取邮箱权限。
我尝试使用以下命令排除访问权限。
PS C:\ Users \ XXXX> get-mailboxpermission-标识'CCCC.XXXX.com/Users/test_50'|选择AccessRights |其中{_.AccessRights -ne“ FullAccess”}
这是我得到的实际结果:
PS C:\Users\XXXX> get-mailboxpermission -Identity 'CCCC.XXXX.com/Users/test_50' |select AccessRights
AccessRights
------------
{FullAccess, ReadPermission}
{FullAccess}
{FullAccess}
{FullAccess}
{FullAccess}
{FullAccess}
{ReadPermission}
{FullAccess, DeleteItem, ReadPermission, ChangePermission, ChangeOwner}
{FullAccess, DeleteItem, ReadPermission, ChangePermission, ChangeOwner}
{FullAccess, DeleteItem, ReadPermission, ChangePermission, ChangeOwner}
{FullAccess, DeleteItem, ReadPermission, ChangePermission, ChangeOwner}
{ReadPermission}
{ReadPermission}
{FullAccess, ReadPermission}
{FullAccess, DeleteItem, ReadPermission, ChangePermission, ChangeOwner}
{ReadPermission}
我会在以下命令中尝试排除“ FullAccess”:
PS C:\Users\XXXX> get-mailboxpermission -Identity 'CCCC.XXXX.com/Users/test_50' |select AccessRights | where { $_.AccessRights -ne "FullAcce
ss"}
AccessRights
------------
{FullAccess, ReadPermission}
{ReadPermission}
{FullAccess, DeleteItem, ReadPermission, ChangePermission, ChangeOwner}
{FullAccess, DeleteItem, ReadPermission, ChangePermission, ChangeOwner}
{FullAccess, DeleteItem, ReadPermission, ChangePermission, ChangeOwner}
{FullAccess, DeleteItem, ReadPermission, ChangePermission, ChangeOwner}
{ReadPermission}
{ReadPermission}
{FullAccess, ReadPermission}
{FullAccess, DeleteItem, ReadPermission, ChangePermission, ChangeOwner}
{ReadPermission}
预期输出:
AccessRights
------------
{ReadPermission}
{ReadPermission}
{DeleteItem, ReadPermission, ChangePermission, ChangeOwner}
{DeleteItem, ReadPermission, ChangePermission, ChangeOwner}
{DeleteItem, ReadPermission, ChangePermission, ChangeOwner}
{DeleteItem, ReadPermission, ChangePermission, ChangeOwner}
{ReadPermission}
{ReadPermission}
{ReadPermission}
{DeleteItem, ReadPermission, ChangePermission, ChangeOwner}
{ReadPermission}
答案 0 :(得分:1)
由于您只是尝试过滤输出,因此-replace
运算符和.where()
方法的组合就足够了。
(get-mailboxpermission -Identity 'CCCC.XXXX.com/Users/test_50' |
Select-Object @{n="AccessRights";e={$_.AccessRights -replace "FullAccess(?:, )?"}}).where{$_.AccessRights -ne ""}
此处的-replace
运算符将用空字符串替换字符串FullAccess,
或FullAccess
。 .where()
方法删除仅包含空字符串的行。由于替换使用的是正则表达式,因此(?:, )?
被评估为一个非捕获组(?:()
),以逗号匹配,后跟空格零或一次(?
)。
Select-Object
命令正在使用哈希表来保存AccessRights
标头名称,同时处理管道对象。