【问题标题】:Exchange 2010 Powershell - Return Users With SendAs Permissions But Filter Disabled UsersExchange 2010 Powershell - 返回具有 SendAs 权限但过滤禁用用户的用户
【发布时间】:2020-12-01 16:31:20
【问题描述】:

所以我有一个运行良好的脚本,我在网上找到并根据我的需要进行了更改。我在下面粘贴了这个脚本。但是,在输出中有许多对邮箱具有权限的禁用用户。例如。我会得到一个像“邮箱名称^Mailbox@email.com^ActiveUser ActiveUser DisabledUser”这样的输出所以我想知道是否有办法让脚本跳过禁用用户,就像它忽略自我权限一样。

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
. $env:ExchangeInstallPath\bin\RemoteExchange.ps1
Connect-ExchangeServer -auto

$OutFile = “C:\Send_As_Permissions.txt”
“DisplayName” + “^” + “Email Address” + “^” + “Send As” | Out-File $OutFile -Force
 
$Mailboxes = Get-Mailbox -resultsize unlimited | Select Identity, Alias, DisplayName, DistinguishedName, WindowsEmailAddress
ForEach ($Mailbox in $Mailboxes) {
    $SendAs = Get-ADPermission $Mailbox.identity | where {($_.ExtendedRights -like “*Send-As*”) -and -not ($_.User -like “NT AUTHORITY\SELF”) -and -not ($_.User -like “s-1-5-21*”)} | % {$_.User}
    $Mailbox.DisplayName + “^” + $Mailbox.WindowsEmailAddress + “^” + $SendAs | Out-File $OutFile -Append
}

【问题讨论】:

    标签: powershell exchange-server-2010


    【解决方案1】:

    如果您只想报告已启用的邮箱,请在 IsMailboxEnabled 属性上过滤来自 Get-Mailbox 的输出:

    $Mailboxes = Get-Mailbox -resultsize unlimited | Where-Object { $_.IsMailboxEnabled } | Select ...
    

    如果您只想报告已启用帐户的个别权限分配,则必须根据您提取的 User 属性的值查询 AD:

    $SendAs = Get-ADPermission $Mailbox.identity | where {($_.ExtendedRights -like “*Send-As*”) -and -not ($_.User -like “NT AUTHORITY\SELF”) -and -not ($_.User -like “s-1-5-21*”)} | % {$_.User}
    
    $domain,$username = $SendAs.Split('\')
    $ADUser = Get-ADUser -Identity $username -Server $domain
    if($ADUser.Enabled){
        # output to report
    }
    

    【讨论】:

    • 嘿,Mathias,遗憾的是,这只会过滤掉禁用的邮箱,而不是对我试图实现的每个邮箱拥有“代理发送”权限的禁用用户。
    • @ItsSimplyEddie 抱歉,我误读了原始请求。我已经更新了答案,但您可能还需要为组添加一些处理:)
    • 完全不用担心。新答案看起来很有希望,但出于某种原因,它似乎不喜欢 Get-ADUser 或 .Split 作为一种方法。
    猜你喜欢
    • 2018-12-20
    • 2018-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-22
    • 2014-11-10
    • 1970-01-01
    相关资源
    最近更新 更多