Hi everybody,
i’m not so fit up with powershell but i have a task.
task:
- find every ADaccount, which is disabled and the distributongroup the ADaccount
belongs to. - delete the determined ADaccounts from the distributongroups.
The ADaccounts itself should not be deleted!
An ADaccount can belong to more then one distributongroup.
I found a script determines the ADaccounts with the distributongroups and i deleted the distributongroups memebership through the Active Directory Administrative Center manually.
Furthermore i got different result for one ADaccount because the ADaccount belongs to two or three distributiongroups.
the script:
$groups = Get-DistributionGroup -ResultSize Unlimited
$report = foreach($group in $groups){
Get-DistributionGroupMember $group |
?{$_.RecipientType -like 'User' -and $_.ResourceType -eq $null} |
Get-User | ?{$_.UserAccountControl -match 'AccountDisabled'} |
Select-Object Name,RecipientType,@{n='Group';e={$group}}
}
Does anyone have solution for that?
This is exchange 2013 on-premise.
Thanks a lot a best regards