when I try to run this code
[pre]
$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
}
[/pre]
I’m getting the following error messages
[pre]
Cannot process argument transformation on parameter ‘Identity’. Cannot convert the “name_of_distributionlist” value of type
“Deserialized.Microsoft.Exchange.Data.Directory.Management.DistributionGroup” to type
“Microsoft.Exchange.Configuration.Tasks.DistributionGroupMemberIdParameter”.
Without the possiblitiy to test I’d suspect Get-DistributionGroupMember is not able to deal with the complete object. So you should provide only the expected property of the object … try the sAMAccountName:
I want to remove the users, but the thing is when a user is leaving the company I can deal with that as long as the account is active. for the already deactivated users I’m strugling to get it to work, because I get that error message posted in the original post thrown at me
Olaf was correct. The problem with the original syntax is that Get-DistributionGroupMember returns a deserialized object which is being passed to the Remove-DistributionGroupMember’s -Identity parameter. Looking at the help for this cmdlet show you what properties you can pass to it. I have put them here: -Identity <DistributionGroupIdParameter>
The Identity parameter specifies the distribution group or mail-enabled security group that you want to modify. You can use
any value that uniquely identifies the group.
For example: * Name, * Display name, * Alias, * Distinguished name (DN), * Canonical DN, * Email address or * GUID
You are most likely having an issue because when the account is inactive it has been removed and it sitting in the dumpster which is retained for 30 days after the account is removed. Bigger question is the user on any sort of time based or Lithold?
[/pre]
I get the following error message
[pre]
The operation couldn’t be performed because object ‘user@mydomain.com’ couldn’t be found on
‘xxxxxx.PROD.OUTLOOK.COM’.
Because when they are inactive they don’t have an exchange account and the mailbox is marked inactive and in the dumpster. All exchange attributes are removed unless you activate it, assign a license and move the mailbox out of the dumpster. You will want to remove them from all groups before you mark them inactive or remove them to minimize the risk of leaving objects in your gal or orphaned objects.