需要PowerShell脚本才能在Exchange 2010中自动隐藏GAL中禁用的用户

我正在寻找一个PS脚本,将自动隐藏所有禁用的用户从GAL。 我跑了下面的命令,但实际上并没有隐藏任何东西,所以我想我一定是错过了一些东西。

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

提前致谢。

试试这个(不是自己运行):

 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命令行pipe理程序。
  • 您将需要更改顶部的“导入模块”行,以指向Exchangepipe理计算机上的Exchange.psm1文件,以使其工作。
  • 我会尝试打印首先要隐藏的用户帐户,以确保在configuration邮箱之前它将影响您认为是的用户。 (把一个#放在pipe道前面的设置邮箱来评论这部分)