限制按对象单元执行管道

时间:2016-11-11 13:05:50

标签: powershell exchange-server exchange-server-2010

我正在使用PowerShell脚本获取具有完全邮箱访问权限的所有用户的列表,并且只需要通过一个对象单元来限制它。但是,我自己的修改没有带来正确的结果,脚本仍在所有用户上运行:

Get-Mailbox -ResultSize Unlimited | Get-MailboxPermission |
 where {$_.OrganizationalUnit -eq “Contoso.com/Users/test/" -and $_.user.tostring() -ne "NT AUTHORITY\SELF" -and $_.IsInherited -eq $false} |
 Select Identity,User,@{Name='Access Rights';Expression={[string]::join(', ', $_.AccessRights)}} |
 Export-Csv -NoTypeInformation \\sharename\mailboxpermissions.csv

2 个答案:

答案 0 :(得分:0)

只需添加另一个select,您只需选择一个对象:

Get-Mailbox -ResultSize Unlimited | 
    Get-MailboxPermission | 
    where {$_.OrganizationalUnit -eq “Contoso.com/Users/test/" -and $_.user.tostring() -ne "NT AUTHORITY\SELF" -and $_.IsInherited -eq $false} | 
    Select -first 1 |
    Select Identity,User,@{Name='Access Rights';Expression={[string]::join(', ', $_.AccessRights)}} | 
    Export-Csv -NoTypeInformation \\sharename\mailboxpermissions.csv

答案 1 :(得分:0)

最后,使用-organizationalUnit过滤器解决了问题。所以代码应该如下:

  Get-Mailbox -ResultSize Unlimited -organizationalUnit "ou=Users,ou=City,ou=county,dc=domain,dc=com" | Get-MailboxPermission | where {$_.user.tostring() -ne "NT AUTHORITY\SELF" -and $_.IsInherited -eq $false} | Select Identity,User,@{Name='Access Rights';Expression={[string]::join(', ', $_.AccessRights)}} | Export-Csv -NoTypeInformation \\sharename\mailboxpermissions.csv