Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

PS Scripting Error when trying to remove a user from multiple distribution lists

$
0
0

Good Evening,

I'm having an issue when I try to delete 1 user from many distribution lists using power shell. I'm using the following command

$DGs=Get-DistributionGroup|where{(Get-DistributionGroupMember $_ |foreach{$_.PrimarySmtpAddress})-contains "user@domain.com"} foreach( $dg in $DGs){Remove-DistributionGroupMember $dg -Member user@domain.com}

There is NO AD integration with my exchange online environment. 

when I change the user@domain.com to the end user I receive the following error

 

Cannot process argument transformation on parameter 'Identity'. Cannot convert 
value "ACCESS Canadian Help Desk" to type 
"Microsoft.Exchange.Configuration.Tasks.DistributionGroupMemberIdParameter". 
Error: "Cannot convert hashtable to an object of the following type: 
Microsoft.Exchange.Configuration.Tasks.DistributionGroupMemberIdParameter. 
Hashtable-to-Object conversion is not supported in restricted language mode or 
a Data section."
    + CategoryInfo          : InvalidData: (:) [Get-DistributionGroupMember],  
   ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-Distrib 
   utionGroupMember
    + PSComputerName        : pod51048psh.outlook.com

Can someone point me in the direction on where I'm going wrong.

Willard Martin had proposed some answers but I couldn't replay back to his latest answer under dmarsh5. 

Thanks for your assistance


Viewing all articles
Browse latest Browse all 15028

Trending Articles