如何在Exchange 2010中自动从GAL中删除禁用的AD用户

当员工因任何原因离开我们的组织时,我们目前禁用了他们的AD账户,但是不要立即删除它。 但是,问题在于这些用户仍然出现在全局地址列表中。

我确定有一个PowerShell脚本来删除它们,但我想使事情更简化。

我希望这里的某个人能够提供一个更好的方法去closures用户,这个用户在这个过程中会自动从GAL中删除它们。

到目前为止,我可以想到两个可能的解决scheme

  1. 创build一个脚本,每小时运行一个PS脚本,将从GAL中删除禁用的用户。

  2. 使用PS命令将同时禁用用户并将其从GAL中删除。

scheme2可能是更好的select,所以如果有人可以提供帮助,我将不胜感激。

提前致谢。

没有必要重新发明轮子,在petri.co.ilfind这个优雅的解决scheme:

# http://www.petri.co.il/forums/showthread.php?p=109975 # usage: Disable-User [accountname] [enable/disable] function get-dn ($SAMName) { $root = [ADSI]'' $searcher = new-object System.DirectoryServices.DirectorySearcher($root) $searcher.filter = "(&(objectClass=user)(sAMAccountName= $SAMName))" $user = $searcher.findall() if ($user.count -gt 1) { $count = 0 foreach($i in $user) { write-host $count ": " $i.path $count = $count + 1 } $selection = Read-Host "Please select item: " return $user[$selection].path } else { return $user[0].path } } $Name = $args[0] $status = $args[1] $path = get-dn $Name if ($path -ne $null) { "'" + $path + "'" if ($status -match "enable") { # Enable the account $account=[ADSI]$path $account.psbase.invokeset("AccountDisabled", "False") $account.setinfo() Set-Mailbox "$Name" -HiddenFromAddressListsEnabled $False } else { # Disable the account $account=[ADSI]$path $account.psbase.invokeset("AccountDisabled", "True") $account.setinfo() Set-Mailbox "$Name" -HiddenFromAddressListsEnabled $True } } else { write-host "No user account found!" -foregroundcolor white -backgroundcolor red } 

将其保存为Disable-User.ps1并运行.\Disable-User.ps1 SAMaccountname disable

有一个比上面更容易的解决scheme,并且可以在Exchangepipe理控制台中使用Quest AD PowerShell命令行程序时在两行中完成。

 param( [string]$username = $(throw "A user ID is required.") #throw exception if no value provided ) Disable-QADUser -Identity $username -service "dc.domain.local:389" Set-Mailbox -identity "domain\$username" -HiddenFromAddressListsEnabled $true -DomainController "dc.domain.local" 

有一个更简单的方法:

  1. 转到EMC>用户邮箱>属性
  2. 在常规选项卡中,您将看到hide from exchange address listhide from exchange address listcheckbox,请选中此框。
  3. 点击应用

之后没有人能够在GAL中看到那个用户。