none
Script to Update a Distribution Group

    Question

  • I have an on call distribution group with two users. On a weekly basis I want to remove one user and add the next one in rotation.

    My thought is to define all combinations of users (abe and ben, ben and charles, charles and dan, dan and abe), read whose currently in the group (let's say its ben and charles), match that to the defined variable combo, then remove all users and add the next set (in this case charles and dan).

    I know how to define the array, list the current distro group, and remove/add users to the group. How could I enumerate the current group to do the aforementioned comparison? Or is there a better logic flow for me to take?

    The one other wrinkle is that there is a third user who is always apart of the group.

    Thursday, July 12, 2018 4:04 PM

All replies

  • Use a Queue>

    $q = [System.Collections.Queue]::New()
    $q.Enqueue(1)
    $q.Enqueue(2)
    $q.Enqueue(3)
    $q.Dequeue()

    Enqueue all then dequeue one and add it to the list and back into the queue.  It's a FIFO.

    To persist save the queue as an array to a file and reload the file to the Q.


    \_(ツ)_/

    Thursday, July 12, 2018 4:18 PM
    Moderator
  • I suspect that you have this setup as a weekly scheduled task on your DC?

    You could create a switch so that it looks down the list and performs the change for you. PowerShell Switch

    Using an array of the two users to remove and two to add wouldn't affect the user that always needs to be in the group.

    Thursday, July 12, 2018 4:20 PM