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
Solved

Script for creating mail enabled distribution lists

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In-place Upgrading Dirsync to Azure AD Connect
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 …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

808 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