Quantcast
Channel: Microsoft Office 365
Viewing all articles
Browse latest Browse all 17713

Removing disabled users from all distribution groups in Office 365

$
0
0

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...


Viewing all articles
Browse latest Browse all 17713

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>