locked
Distribution Group Members RRS feed

  • Question

  • Is there a way to make a distribution group that is only active on certain days? At my company we have techs that are on call only certain days of the week and currently we have to add and remove members every Monday to change who gets service call e-mails.  Just wondering if there was an easier way to do this?
    Thursday, April 10, 2014 3:01 PM

Answers

  • You can script it and use the Task Scheduler to run that script.  But if you have personnel changes, you would need to figure out how to handle that in your script.
    Thursday, April 10, 2014 6:02 PM
  • Is it always the same set of people that are on call on certain days? If is, it shouldn't that hard to use a CSV file with their names and days they're on call to script the replacement of the DL membership every day.

    Something like this:

    $oncall=@()
    $today = "{0:dddd}" -f {get-date}
    import-csv "on-call.csv" | foreach {
      if ($_.day -eq $today)
      {
        $oncall += (get-user $_.name).distinguishedname
      }
    }
    $gdn=(get-distributiongroup "on-call-group").distinguishedname
    $g=[ADSI]"LDAP://$gdn"
    $g.members = $oncall
    $g.setinfo()


    --- Rich Matheisen MCSE&I, Exchange MVP

    Friday, April 11, 2014 2:31 AM
  • Provided the number of members on the group is less than the default page size in the AD (probably 1500) it works quickly.

    If the number of members exceeds the default page size of the AD then I believe you'd have to use the "PutEx(...)" method (or maybe the "Range(...)" method).

    I figured the membership would be pretty small so I took the easy way out. :-)

    The ActiveSync module's Set-ADGroup could probable do it with the -Clear and -Add parameters without resorting to ADSI, but I figured why not provide an answer that works for every release that allows the use of Powershell to manage Exchange.


    --- Rich Matheisen MCSE&I, Exchange MVP

    Friday, April 11, 2014 10:00 PM

All replies

  • You can script it and use the Task Scheduler to run that script.  But if you have personnel changes, you would need to figure out how to handle that in your script.
    Thursday, April 10, 2014 6:02 PM
  • Is it always the same set of people that are on call on certain days? If is, it shouldn't that hard to use a CSV file with their names and days they're on call to script the replacement of the DL membership every day.

    Something like this:

    $oncall=@()
    $today = "{0:dddd}" -f {get-date}
    import-csv "on-call.csv" | foreach {
      if ($_.day -eq $today)
      {
        $oncall += (get-user $_.name).distinguishedname
      }
    }
    $gdn=(get-distributiongroup "on-call-group").distinguishedname
    $g=[ADSI]"LDAP://$gdn"
    $g.members = $oncall
    $g.setinfo()


    --- Rich Matheisen MCSE&I, Exchange MVP

    Friday, April 11, 2014 2:31 AM
  • Hi,

    Actually, we have a dedicated support team regarding Script. I recommend you ask your question on the Script forum which is staffed by more experts specializing in this kind of problems. You might get a better help there. Thanks for understanding.

    http://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?category=scripting

    Best regards,


    Belinda Ma
    TechNet Community Support

    Friday, April 11, 2014 8:09 AM
    Moderator
  • I'll make a comment on Rich's script above - since it only opens the distribution group to replace the membership, it will complete a lot faster than removing and adding the members individually (especially on very large DLs, though I doubt the one being discussed here is very large).  Pity we don't have an Exchange cmdlet that does the same.
    Friday, April 11, 2014 12:11 PM
  • Provided the number of members on the group is less than the default page size in the AD (probably 1500) it works quickly.

    If the number of members exceeds the default page size of the AD then I believe you'd have to use the "PutEx(...)" method (or maybe the "Range(...)" method).

    I figured the membership would be pretty small so I took the easy way out. :-)

    The ActiveSync module's Set-ADGroup could probable do it with the -Clear and -Add parameters without resorting to ADSI, but I figured why not provide an answer that works for every release that allows the use of Powershell to manage Exchange.


    --- Rich Matheisen MCSE&I, Exchange MVP

    Friday, April 11, 2014 10:00 PM