Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Script for creating mail enabled distribution lists

Posted on 2008-10-14
4
Medium Priority
?
298 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
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…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

971 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