Assistance with script

First I would like to say that I am new to PowerShell, but I am learning and trying.

I’m trying to run the following script:

$dgm = Get-DistributionGroupMember -Identity "[DL] CP LO" | where {$_.RecipientType -eq "User"}

foreach ($user in $dgm)
Remove-DistributionGroupMember -Identity "[DL] CP LO" -Member $user -Confirm:$false


And I am getting the following error:

Cannot process argument transformation on parameter ‘Member’. Cannot convert the “Lisa Bringel” value of type “Deserialized.Microsoft.Exchange.Data.Directory.Management.ReducedRecipient” to type

  • CategoryInfo : InvalidData: (:slight_smile: [Remove-DistributionGroupMember], ParameterBindin…mationException
  • FullyQualifiedErrorId : ParameterArgumentTransformationError,Remove-DistributionGroupMember
  • PSComputerName :

I am unsure what I’m doing wrong. Any assistance is appreciated.

I don’t have an exchange environment to test your code, but I think I know what is going on based on the error message and a little research into the data types in question. The Get-DistributionGroupMember cmdlet returns “ReducedRecipient” type objects. After running line 1, $dgm will be an array of those objects. You can test this by piping the variable to Get-Member and it will tell you what type of objects are contained in the array along with the properties and methods of those objects which is important for the issue you are having because on line 5 you are passing a “ReducedRecipient” type object to the “Member” parameter which expects to receive a “GeneralRecipientIDParameter”. According to the documentation you can use any value the uniquely identifies the recipient. Basically you need to find a property of your “ReducedRecipient” object ($user) that does just that. I think the name property would work, but can’t verify it on my machine, if not I’m sure there is another property that would meet the requirement.

Remove-DistributionGroupMember -Identity "[DL] CP LO" -Member $ -Confirm:$false


Thank you Mike R., the $ worked great.

I really do want to thank you for taking the time to “teach” so I can continue to learn and move forward. I have posted on other sites and the main response is to get get some training or look in a book. I had searched the “Google’s” and didn’t find a resolution, just more errors. So thank you again for taking the time to help me, and maybe some other newbies, to learn.