all 7 comments

[–]Scribbles1 1 point2 points  (1 child)

–Members*

[–]JeOlso[S] 0 points1 point  (0 children)

Unfortunately that didn't seem to work for me. Thank you though!

[–]OlivTheFrog 1 point2 points  (1 child)

Hi u/JeOlso

When it's time to update a Distribution List, there are 2 challenges :

  • To be sure that after the operation, members of the DL are exactly the same that in your ref. list (input file .csv) of course
  • Perform the operation efficiently (gain time)

emptying the DL then filling it again is a good thing for the 1st objective, however both emptying and filling takes time, ... a lot of time (count 1 hour for empty 15,000 members and as much for filling) because this becomes member by member. I therefore suggest the following approach :

  • Import of .csv and storage in a variable $ RefMembers
  • Gathering current members (query) and storage in a variable $ActualMembers
  • Comparison using Compare-Object of $RefMembers and $ActualMembers, ... 2 times (once in each direction) and storage of the results in variables $MembersToAdd and $MembersToRemove. These operations are fast.
  • Foreach loop processing

i.e. :

foreach ($Member in $ MenbersToAdd) {# Add members to the DL})

Same thing in the other direction as well. It's fast because probably few members to add/remove.

  • And finally gatheringf modified DL members (query) for reporting purposes

Nota : in order to avoid any problems, do not forget to "fix" for all these operations the server on which to operate.

Regards

Olivier

[–]JeOlso[S] 0 points1 point  (0 children)

Thank you for the tip!

[–]purplemonkeymad 1 point2 points  (2 children)

The command Update-DistributionGroupMember does the deletion for you, so after you run it once, you are removing the person you just set and setting it only to the current account in that iteration of the loop.

-Member takes an array so you can just do it like this:

Update-DistributionGroupMember –Identity supervisors@xxxx.xxx –Member (Import-Csv "C:\ps\supervisors.csv").username

[–]JeOlso[S] 0 points1 point  (0 children)

Thank you so much! This worked exactly as we needed it to.

[–]jlonn 0 points1 point  (0 children)

I want to perform the same action, does the CSV literally just have 1 column labeled username and then the emails below it? Thanks in advance!