Solved

Script for creating mail enabled distribution lists

Posted on 2008-10-14
4
265 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Creating and Managing Databases with phpMyAdmin in cPanel.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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 …

758 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

21 Experts available now in Live!

Get 1:1 Help Now