I have a project where we need to remove a large number of disabled users from a large number of distribution groups. It was brought to my attention that a coworker was going through the groups and manually removing the disabled users, I know there must be an easier way, I have tried running these commands:
$Groups = Get-DistributionGroup -ResultSize Unlimited
foreach ($group in $groups){Get-DistributionGroupMember $group | ?{$_.RecipientType -like '*User*' -and $_.ResourceType -eq $null} | Get-User | ?{$_.UserAccountControl -match 'AccountDisabled'} | Remove-DistributionGroupMember $group -Confirm:$false}
The result is the following:
Cannot process argument transformation on parameter 'Identity'. Cannot convert value "Group X" to type
"Microsoft.Exchange.Configuration.Tasks.DistributionGroupMemberIdParameter". Error: "Cannot convert...