Solved

Script for creating mail enabled distribution lists

Posted on 2008-10-14
4
269 Views
Last Modified: 2013-12-24
Hello,

I'm cleaning up AD mail enabled security groups. I want to remove their Exchange attributes so they are no longer mail enabled. However I would like to create the same name and append _DL . This way all AD objects with _DL will be mail enabled Global Ditribution lists. The members have to be copied over.
For example:
We now have in AD the Group "IT Dept" which is a mail enabled Global Security Group. We have 10 users in the member field added. So someone can write to "IT Dept@domain.com" and the 10 members get the email.
I would like to change it to:                      
"IT Dept_DL" and make it a Mail enabled Global Distribution Group and have all the 10 users copied over.

Because I have about 187 groups to do is there a way to have a script running that will do this instead of me doing it manually?

I found a script in the forum that enables me to do just what I want but there is no txt file that references all the groups.

Here it is:

@echo off
setlocal
 
set oldgroupdn=cn=it_test,ou=it Groups,dc=lab,dc=com
set newgroupdn=cn=it_test_DL,ou=it Groups,dc=lab,dc=com
 
dsadd group "%newgroupdn%" -secgrp no -scope g
dsget group "%oldgroupdn%" -members | dsmod group "%newgroupdn%" -addmbr

Where can I reference in the script a txt file with all the groups?

Tacobell2000
0
Comment
Question by:Tacobell2000
  • 2
4 Comments
 
LVL 31

Expert Comment

by:Henrik Johansson
ID: 22724375
See ExchMbx on following link for command line utility for exchange tasks:
http://www.joeware.net/freetools/tools/exchmbx/

The snippet below should do what you want.
groups.txt includes group names, one per line.
Script expect OU-base for new group as first argument.
@echo off

set OUBASE=%~1

for /F %%a in (groups.txt) do (

  dsadd group "DN=%%a_DL,%OUBASE%" -secgrp no -scope g

  dsquery group -name %%a | dsget group -members | dsmod group "CN=%%a_DL,%OUBASE%" -addmbr

  exchmbx -b "CN=%%a_DL,%OUBASE%" -me %%a@domain.com

)

Open in new window

0
 

Author Comment

by:Tacobell2000
ID: 22725125
ok...I copied and pasted this into notepad and renamed the extension cmd. Created a group.txt and put it in the root of the c drive. Double clicked on the cmd file and nothing happened.

@echo off

set OUBASE=%~1

for /F %%a in (groups.txt) do (

  dsadd group "DN=%%a_DL,%OUBASE%" -secgrp no -scope g

  dsquery group -name %%a | dsget group -members | dsmod group "CN=%%a_DL,%OUBASE%" -addmbr

  exchmbx -b "CN=%%a_DL,%OUBASE%" -me %%a@domain.com

)

 

Open in New Window Select All Accept as Solution 

Open in new window

0
 
LVL 31

Accepted Solution

by:
Henrik Johansson earned 500 total points
ID: 22736332
The 'SET OUBASE=%~1' means that it sets OU-base to be first argument of the script and you nead to run it from the command prompt like below:
C:\>extension.cmd "OU=..."

Or change the 'SET OUBASE=' line to have a static value instead of %~1.
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now