我正在寻找一个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 } }
笔记:
#放在pipe道前面的设置邮箱来评论这部分)