#从邮件组发送列表中删除已离职人员 Add-PSSnapin microsoft.exchange* Import-Module activedirectory $RemoveGroupSenderslog = "D:ScriptsRemove.log" #从通讯组发送列表中删除已离职人员 $txzs = Get-DistributionGroup foreach ($g in $txzs) { #导出该邮件组的发件人列表 $fromSenders = $g.AcceptMessagesOnlyFrom [array]$fromSenders_false = $none foreach ($user in $fromSenders) { $userinfor = get-aduser $user.DistinguishedName #判断用户是否离职 if ($userinfor.enabled -eq $false) { $fromSenders_false += $userinfor.SamAccountName } } #判断是否有已离职人员存在 if ($fromSenders_false.count -gt 0) { #从邮件组发送列表中删除已离职人员 $now = get-date -UFormat "%Y-%m-%d %H:%M:%S" $galias = $g.Alias $galias "$now GroupName: $galias" |out-file $RemoveGroupSenderslog -append $fromSenders_false |out-file $RemoveGroupSenderslog -append Set-DistributionGroup -Identity $g.Alias -AcceptMessagesOnlyFrom @{remove=$fromSenders_false} } }