Solved

Script for creating mail enabled distribution lists

Posted on 2008-10-14
4
282 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
[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
  • 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
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…

734 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