【问题标题】:Limit executing pipeline by object unit按对象单元限制执行管道
【发布时间】:2017-03-25 17:25:22
【问题描述】:

我正在使用 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

【问题讨论】:

  • “一个对象单元”是什么意思?
  • 只是 Active Directory 中的一个常规对象单元。表示特定对象单元不是 Exchange 上的所有邮箱。

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


【解决方案1】:

只需添加另一个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

【讨论】:

  • 嗨马丁,谢谢你的回答。刚刚尝试了您的代码,但仍然看到该脚本正在所有邮箱上运行。
  • 你检查过 CSV 吗?
  • csv 为空,脚本在很长一段时间后因错误而中断,这并不奇怪,因为 powershell 进程需要大约 5Gb 的内存!
【解决方案2】:

最后,使用 -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 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-15
    • 1970-01-01
    • 1970-01-01
    • 2011-05-08
    • 1970-01-01
    • 2018-08-03
    相关资源
    最近更新 更多