none
Delete all users from distribution group and then repopulate via script nightly RRS feed

  • Question

  • A CSV file is generated nightly with changes to employee positions, locations, etc.  Based on this information we then add the employees to specific distribution groups.  I have written a powershell script to remove all users from a distribution group and then re-add them from this CSV file.  I would like to know if this will cause any replication issues throughout Active Directory by deleting all users and then adding them again?  I am located at a main data center site and we have nearly 300 small sites with domain controllers.  Below is a generic and simplified version of the powershell script.  I would appreciate any input.

    -Glen-

    get-distributiongroupmember “DistributionGroupName” | Remove-DistributionGroupMember “DistributionGroupName” -confirm:$false
    import-csv C:\CSVFileName.csv | foreach {If ($_.Parameter -eq "Value" {add-distributiongroupmember -id "DistributionGroupName" -member $_.NetworkIDx}}

    Tuesday, July 19, 2011 8:57 PM

All replies

  • As far i understand and as far you dont have multiple exchagne sites,  Removing and adding user to DL will not make any replication issues.

    Exchange Server will use the DC from its own site always untile its not reachable/available. and DL expansion is happenng on Exchagne Server. nothing much to do with DC to DC replicaiton.


    Thanks & Regards, Sandheep [...:::""I can't do it" never yet accomplished anything; "I will try" has performed wonders ":::...]
    Tuesday, July 19, 2011 9:12 PM
  • What are the implications of having two Exchange sites?  We have Exchange Client Access, Hub Transport, and Mailbox servers at my site and one other site.

    Tuesday, July 19, 2011 9:45 PM
  • On Tue, 19 Jul 2011 20:57:55 +0000, -Glen- wrote:
     
    >A CSV file is generated nightly with changes to employee positions, locations, etc. Based on this information we then add the employees to specific distribution groups. I have written a powershell script to remove all users from a distribution group and then re-add them from this CSV file. I would like to know if this will cause any replication issues throughout Active Directory by deleting all users and then adding them again?
     
    It won't cause any "issues" but it will generate a fail amount of
    replication traffic to the other DCs.
     
    >I am located at a main data center site and we have nearly 300 small sites with domain controllers. Below is a generic and simplified version of the powershell script. I would appreciate any input.
    >
    >-Glen-
    >
    >get-distributiongroupmember ?DistributionGroupName? | Remove-DistributionGroupMember ?DistributionGroupName? -confirm:$false import-csv C:\CSVFileName.csv | foreach {If ($_.Parameter -eq "Value" {add-distributiongroupmember -id "DistributionGroupName" -member $_.NetworkIDx}}
     
    You can do better by checking to see if the AD object in the members
    property is in the CSV and removing only those that aren't. Do the
    same for the stuff in the CSV -- if it isn't in the members property,
    add it. The script will be more complex than what you have now, but if
    the AD is capable of doing link value replication you'll only
    replicate the changes rather than the entire membership of the DL.
    Unless you have a huge "churn" in the DL membership the replication to
    all those other DCs will be considerably less.
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    Wednesday, July 20, 2011 1:11 AM
  • Any pointers as to how I go about doing this?  I am not the strongest scripter.
    Wednesday, July 20, 2011 9:19 PM
  • >>I would like to know if this will cause any replication issues throughout Active Directory by deleting all users and then adding them again?


    Of course, it will cause replication flow.

    When you rename or move a member of a group (and that member resides in a different domain from the group), the group may temporarily appear not to contain that member. The infrastructure master of the group's domain is responsible for updating the group so that it knows the new name or location of the member.

    Infrastructure master

    Thursday, July 21, 2011 2:50 AM
  • If you have exchange servers in multiple site, there will be replication issues.(if you have good bandwidth between your sites, you can ignore this. If I am not wrong normal site to site replication polling interval is 15 min)

    if you have 2 site and only one site have the exchange servers, as far when it concerns to DL no replciation issues.

    And of-course it will generate more AD replication data but that will not be an issue as long you have good bandwidth between 2 site.

    Consider Rich's point about adding/removing the users after checking the existing membership.


    Also, you can think of Dynamic Distribution List. which will automatically populate the group membership as the mails comes in. However if there is frequent mail to these DLs, i wont recommend for DDL.



    Thanks & Regards, Sandheep [...:::""I can't do it" never yet accomplished anything; "I will try" has performed wonders ":::...]
    Thursday, July 21, 2011 4:52 AM
  • Again how do I go about scripting this via powershell so it will compare?  As far as bandwidth between the two Exchange sites, yes it is sufficient.  We have a 1 Gb primary and a 500 Mb secondary.
    Thursday, July 21, 2011 6:37 PM
  • On Tue, 19 Jul 2011 21:45:56 +0000, -Glen- wrote:
     
    >What are the implications of having two Exchange sites? We have Exchange Client Access, Hub Transport, and Mailbox servers at my site and one other site.
     
    Forget Exchange. This is an AD question.
     
    You said "we have nearly 300 small sites with domain controllers".
    That's a LOT of replication for very little change.
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    Thursday, July 21, 2011 9:20 PM
  • On Thu, 21 Jul 2011 04:52:22 +0000, Sandheep - Trying to Understand
    EHLO wrote:
     
    >
    >
    >If you have exchange servers in multiple site, there will be replication issues.(if you have good bandwidth between your sites, you can ignore this. If I am not wrong normal site to site replication polling interval is 15 min)
    >
    >if you have 2 site and only one site have the exchange servers, as far when it concerns to DL no replciation issues.
    >
    >And of-course it will generate more AD replication data but that will not be an issue as long you have good bandwidth between 2 site.
     
    He said he has 300 sites, not 2, each with a DC!
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    Thursday, July 21, 2011 9:22 PM
  • On Thu, 21 Jul 2011 18:37:33 +0000, -Glen- wrote:
     
    >Again how do I go about scripting this via powershell so it will compare? As far as bandwidth between the two Exchange sites, yes it is sufficient. We have a 1 Gb primary and a 500 Mb secondary.
     
    In general terms, you could you this as a model:
     
    Get the group membership using ADSI. That'll get you just the DNs of
    the members. Load it into a hash using the DN as the key and, say, "?"
    as the value.
     
    Using the names in your SV, get the distinguished name of each
    recipinet and load them into another hash. Put something into the
    value for each key ("?" works equally well, here).
     
    Iterate over the groups membership and for each DN, find the
    corresponding DN in the hash from the CSV. If it's not present, remove
    the DN from the group (no need to remove it from the hash). That'll
    take care of removing the recipients that shouldn't be there.
     
    Interate over the hash populated with the DNs from the CSV. Check each
    DN against the hash of the DNs from the group. If you don't find it in
    the hash, add it to the group. That'll take care of adding the
    recipients that should be in the group bu aren't.
     
    Done.
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    Thursday, July 21, 2011 9:31 PM
  • I attempted to use this code and got the following error any info on that. Using latest powershell version and Exchange Online DL 

    Running this command 

    get-distributiongroupmember “DistributionGroupName” | Remove-DistributionGroupMember “DistributionGroupName” -confirm:$false

    I get the following error:

    The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the 
    parameters that take pipeline input

    Any Help is greatly appreciated. 

    Thursday, January 31, 2019 5:48 PM
  • I know it´s a bit late but maybe it will help someone. I´m using this:

    Get-DistributionGroupMember -Identity $group | % {Remove-DistributionGroupMember -Identity $group -Member $_.DistinguishedName -Confirm:$false}
    

    • Proposed as answer by LMSU Tuesday, March 31, 2020 7:31 AM
    Wednesday, April 24, 2019 1:35 PM
  • Great!

    Thanks for your effort.

    its worked for me. 

    I have created below PS Script to remove all User whose doesnt have mailbox

    $DG=Get-DistributionGroup -Resultsize Unlimited

    foreach ($DGM in $DG)
    {
    $Mem=Get-DistributionGroupMember -identity $DGM.PrimarySmtpAddress | where {$_.RecipientType -eq "User"} 
    foreach ($Rmem in $Mem)
    {
    Remove-DistributionGroupMember -identity $DGM.PrimarySmtpAddress -Member $Rmem.DistinguishedName -Confirm:$Y
    }
    }

    • Edited by Nataraajan Thursday, March 12, 2020 12:44 PM
    Thursday, March 12, 2020 12:19 PM