需要 PowerShell 脚本来自动隐藏 Exchange 2010 中 GAL 中的已禁用用户

需要 PowerShell 脚本来自动隐藏 Exchange 2010 中 GAL 中的已禁用用户

我正在寻找一个 PS 脚本,它可以自动隐藏 GAL 中的所有禁用用户。我运行了以下命令,但它实际上并没有隐藏任何内容,所以我想我一定遗漏了什么。

get-mailbox -ResultSize unlimited | where{$_.UserAccountControl -eq "AccountDisabled, NormalAccount" -and $_.RecipientTypeDetails -eq "UserMailbox"} | Set-Mailbox -HiddenFromAddressListsEnabled $True

提前致谢。

答案1

尝试一下(我自己还没有运行过):

Import-Module C:\Temp\Exchange.psm1
$filter = "(&(objectCategory=person)(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=2))"
$users = ([adsiSearcher]$Filter).findall()
foreach($suser in $users)
    {
    if($suser.properties.item("showInAddressBook") -ne $null) {
        get-mailbox "$($suser.properties.item("sAMAccountName"))" | ? {$_.RecipientType -eq "UserMailbox"} | set-mailbox -HiddenFromAddressListsEnabled $True
    }
}

笔记:

  • 在 Powershell ISE 中运行此程序,而不是 Exchange 命令行管理程序。
  • 您需要将顶部的“Import-Module”行更改为指向 Exchange 管理计算机上的 Exchange.psm1 文件才能使其正常工作。
  • 我会尝试先打印您要隐藏的用户帐户,以确保它会影响您认为在配置邮箱之前的用户。(#在设置邮箱的管道前放置一个以注释掉该部分)

相关内容