Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to script the addition and removal of Distribution Group Members

Posted on 2008-06-25
9
Medium Priority
?
859 Views
Last Modified: 2008-07-18
We're running Exchange 2007 SP1 on a Windows 2003 SP2 server.  We have 3 Distribution Groups that are updated on a weekly basis.  Each Distribution Group only has one member in it.  The Distribution Groups are named: 1st on call, 2nd on call, 3rd on call.  Every Friday, the member that was in the 3rd on call group, moves to 2nd on call.  The member from 2nd on Call, moves to 1st on call.  The member of 1st on call gets removed from the rotation.  

I'm looking for a way to somewhat automate the task of updating these distribution groups.  I've been looking around and found a Powershell script that will import members from a csv file.  But I haven't found a way to remove the member from one group and place them into another.  Below is the sample code I found on this site (I'd credit the author but couldn't find the post again):
import-csv dlmember.csv | foreach {add-distributiongroupmember -identity "dist group name" -member $_.memberAlias}

Any help is greatly appreciated.  Also, this script doesn't have to pull from a csv file if not needed, this is just what I have found so far.  Please let me know if there's need for further clarification

Thanks in advance.
0
Comment
Question by:dmorrisroe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 18

Expert Comment

by:BSonPosh
ID: 21869223
I think this will do it for you (if my logic isnt confused :) )
# Collect Group Members and store in the New Group Collection
$callGroup1 = Get-DistributionGroupMember "3rd on call"
$callGroup2 = Get-DistributionGroupMember "1st on call"
$callGroup3 = Get-DistributionGroupMember "2nd on call"
 
# Add users for new Collection to Groups
$callgroup1 | %{$_.distinguishedname} | Add-DistributionGroupMember "1st on call"
$callgroup2 | %{$_.distinguishedname} | Add-DistributionGroupMember "2nd on call"
$callgroup3 | %{$_.distinguishedname} | Add-DistributionGroupMember "3rd on call"

Open in new window

0
 
LVL 18

Expert Comment

by:BSonPosh
ID: 21869244
btw... if the group membership is static.

Perhaps a better way is renaming the groups... This would save a potentially significant amount of AD replication.
0
 
LVL 4

Author Comment

by:dmorrisroe
ID: 21869309
Thanks, I'll give the script a try in about a half an hour.  Unfortunately, membership isn't static.  It's a rotation of about 5 people.
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 18

Expert Comment

by:BSonPosh
ID: 21910299
How did this work out for you?
0
 
LVL 1

Expert Comment

by:Robert Davis
ID: 21960860
I am wondering the same thing....
0
 
LVL 4

Author Comment

by:dmorrisroe
ID: 22006587
sorry for the delay.  I ran the script but none of the distribution list had changed.  
0
 
LVL 18

Accepted Solution

by:
BSonPosh earned 2000 total points
ID: 22007898
any error? It is unlikely that it failed without an error of some sort.

Run this script

# Collect Group Members and store in the New Group Collection
$callGroup1 = Get-DistributionGroupMember "3rd on call"
$callGroup2 = Get-DistributionGroupMember "1st on call"
$callGroup3 = Get-DistributionGroupMember "2nd on call"
 
# Add users for new Collection to Groups
$callgroup1 | %{$_.distinguishedname} | Add-DistributionGroupMember "1st on call"
$callgroup2 | %{$_.distinguishedname} | Add-DistributionGroupMember "2nd on call"
$callgroup3 | %{$_.distinguishedname} | Add-DistributionGroupMember "3rd on call"
 
if(!$?){$error[0]}

Open in new window

0
 
LVL 4

Author Comment

by:dmorrisroe
ID: 22011213
Sorry, it's was on my part.  The error read: Add-DistributionGroupMember : The group "1st on call" is not a mail-enabled u
niversal group.  I made it universal and it started to switch members.  However, it moved them like this:
1st to 2nd
2nd to 3rd
3rd to 1st.

I think I should be able to flip that around.
0
 
LVL 18

Expert Comment

by:BSonPosh
ID: 22011269
k
0

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A bad practice commonly found during an account life cycle is to set its password to an initial, insecure password. The Password Reset Tool was developed to make the password reset process easier and more secure.
Wouldn't it be nice if objects in Active Directory automatically moved into the correct Organizational Units? This is what AutoAD aims to do and as a plus, it automatically creates Sites, Subnets, and Organizational Units.
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question