VB script to update distribution list

Need a VB script which will update "XYZ" distribution list membership from the related security group. All members (users and groups) of the distribution group are removed first.Then the related security group is fully expanded to include all members (users and groups). Finally, the members (users and groups) are added from the related security group
mahesh_gowdaAsked:
Who is Participating?
 
Chris DentConnect With a Mentor PowerShell DeveloperCommented:

Sure, if you like.

You'll need to make some changes, hopefully it should be obvious enough where :)

Chris

Set objSourceGroup = GetObject("LDAP://CN=Source Group Name,OU=somewhere,DC=yourdomain,DC=com")
Set objDestGroup = GetObject("LDAP://CN=Dest Group Name,OU=somewhere,DC=yourdomain,DC=com")
 
objDestGroup.Put "member", objSourceGroup.GetEx("member")
objDestGroup.SetInfo
 
Set objSourceGroup = Nothing
 
Set objMail = CreateObject("CDO.Message")
 
' SMTP server
strServer = "yourmailserver"
 
' To / From and Subject for the message
objMail.To = "someone@yourdomain.com"
objMail.From = "someone@somewhere.com"
objMail.Subject = "Group Update"
 
' Message Body
' Just e-mails a list of current members
objMail.TextBody = "Updated group membership for " & objDstGroup.Get("name") & vbCrLf & vbCrLf & _
  "Members:" & vbCrLf & Join(objDestGroup.GetEx("member"), vbCrLf)
 
objMail.Configuration.Fields.Item _
  ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMail.Configuration.Fields.Item _
  ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strServer
objMail.Configuration.Fields.Item _
  ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
 
objMail.Configuration.Fields.Update
objMail.Send
Set objMail = Nothing
 
Set objDestGroup = Nothing

Open in new window

0
 
kjanickeCommented:
Couldn't you just mail enable the security group, and use one group for both purposes?
0
 
Chris DentPowerShell DeveloperCommented:

Depending on your aim, it could be as simple as this. It simply overwrites the membership of the Destination Group with that from the Source Group.

Chris

Set objSourceGroup = GetObject("LDAP://CN=Source Group Name,OU=somewhere,DC=yourdomain,DC=com")
Set objDestGroup = GetObject("LDAP://CN=Dest Group Name,OU=somewhere,DC=yourdomain,DC=com")
 
objDestGroup.Put "member", objSourceGroup.GetEx("member")
objDestGroup.SetInfo

Open in new window

0
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.

 
mahesh_gowdaAuthor Commented:
Hello Sage,
                    Thank you for your reply. We need to remove the member and we want the security group to expand fully to include all members. Can you let me know on this.
0
 
Chris DentPowerShell DeveloperCommented:

What do you mean by expand fully to include all members?

The above already removes existing members, simply because it completely overwrites any current membership.

Chris
0
 
mahesh_gowdaAuthor Commented:
Hello Chris,
                  Thank you!!  Is there a possibility for us to get a mail once the update is done? Can you help me on that?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.