update-distributiongroupmember doesn't work with powershell script

Marco Mandricardo 21 Reputation points
2022-12-16T16:47:09.583+00:00

Hi,
i'm doing a script to get security group user to update distribution group member,
when i execute the command with manual value, it works and update tehe
but when i execute from script it doesn't work.

this is the command: update-distributiongroupmember -identity "$DL" -Confirm:$false -BypassSecurityGroupManagerCheck -Members $listaemail

here the error, where the couldn't find object is the value of my $listaemail

Write-ErrorMessage : Ex94914C|Microsoft.Exchange.Configuration.Tasks.ManagementObjectNotFoundException|Couldn't find object   
"albert*******,samuele*********,marco*********,giacom********,matteo****". Please make sure that it was spelled correctly or specify a different object.  
At C:\Users\admi*******\AppData\Local\Temp\8\tmpEXO_4gcss23m.kg0\tmpEXO_4gcss23m.kg0.psm1:1092 char:13  
+             Write-ErrorMessage $ErrorObject  
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
    + CategoryInfo          : NotSpecified: (:) [Update-DistributionGroupMember], ManagementObjectNotFoundException  
    + FullyQualifiedErrorId : [Server=DU0PR08MB7738,RequestId=1439f618-8f46-0d80-887c-bcbbbaae1b76,TimeStamp=Fri, 16 Dec 2022 16:18:54 GMT],Write-ErrorMessage  
   

i hide email address, but it will compare with "name.surname@keyman .ext,name.surname@keyman .ext" ecc..

someone can explain this issue?

thanks

Exchange Online
Exchange Online
A Microsoft email and calendaring hosted service.
6,178 questions
Windows for business | Windows Client for IT Pros | Directory services | Active Directory
Windows for business | Windows Server | User experience | PowerShell
{count} votes

Accepted answer
  1. Vasil Michev 119.6K Reputation points MVP Volunteer Moderator
    2022-12-16T19:31:07.58+00:00

    You seem to be passing a string value for the Members parameter, make sure to pass an array instead. I.e. this will not work:

    Update-DistributionGroupMember -Identity DG -Confirm:$false -BypassSecurityGroupManagerCheck -Members "user1,user2"  
    

    but this will:

    Update-DistributionGroupMember -Identity DG -Confirm:$false -BypassSecurityGroupManagerCheck -Members @("user1","user2")  
    
    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Yuki Sun-MSFT 41,376 Reputation points Moderator
    2022-12-19T05:44:26.957+00:00

    Hi @Marco Mandricardo

    Based on your description, are you attempting to bulk update group members for multiple distribution groups? If this is the case, based on my test, you can consider preparing a csv file let's say list.csv which contains the groups and members, like below:
    (one column is the name of the distribution groups, the other column is the member list which is seperated by ",".)
    271962-1.png

    Then run the following command to make the change:

    Import-Csv -Path C:\list.csv  | %{  
        Update-DistributionGroupMember -Identity $_.group -Members ($_.member -split ",") -Confirm:$false  
    }  
    

    If the above cannot meet your requirement, as said earlier, you can try sharing more details for further discussion.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.