Solved

Export Distribution Groups and members to csv file

Posted on 2010-09-02
4
2,237 Views
Last Modified: 2012-05-10
Hi.  I'd like to export all of our universal distribution groups and corresponding members to a csv file. So one big output for everything to a single file.  Is there a command that can do this?

My active directory is on Win 2003 R2.

Any help would be appreciated - thanks!  
0
Comment
Question by:dbrueckner
4 Comments
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 33590801
You can use the following PowerShell command...
Get-DistributionGroupMember -identity "distribution group name" | Export-Csv C:\MyFile.Csv

Also refer to this link..
http://www.ucblogs.net/blogs/exchange/archive/2008/07/03/Exporting-distribution-list-membership-to-Excel.aspx
0
 

Author Comment

by:dbrueckner
ID: 33590847
do you know if there is a way or wild card so that a single command will run through all the distribution groups at once to a single file?  that was what i was looking for.
0
 
LVL 3

Accepted Solution

by:
avalenzuela earned 250 total points
ID: 33590887
You could use something like this
to get all groups to a Text File..

dsquery group "DC=MyDomain,dc=com" -limit 2000 > MyGroups.txt

Then using that list of groups you do the following..

dsget group 'Each_one_Of_My_groups" -members -expand > FileWithmembers.txt



This is a batch file that I have been using...

------ batch file 1 ------------
 Set Data=Groupmembership.txt

 dsquery group "DC=MyDomain,dc=com"  > MyGroups.txt

 For /F "delims=&" %%i in (MyGroups.txt) do Call GroupUsers.bat %%i %Data%
--------------


---------GroupUsers.bat------------

SET  GR=%1
SET  TO=%2
SET  FL=Temp.txt

REM This command dumps every user for Group %GR% to a file %FL%

        dsget group %GR% -members -expand > %FL%

REM This command send every user on the  last file to a new file %TO%
REM and the appends  the group name to the user name   %%i is the username, %GR% is the group

FOR /F  "delims=^" %%i in (%FL%) do @echo %%i%GR% >> %TO%

---------GroupUsers.bat------------














0
 
LVL 57

Expert Comment

by:Mike Kline
ID: 33591005
See this question I helped with last year

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24328572.html

I used adfind in my example; the vbscript ended up being picked....both should work.  I didn't test Tony's script but he is a top guy and is scripts are solid.

Thanks

Mike
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Installing a printer using group policy preferences is not that hard let’s take a look at it. First lets open up your group policy console and edit the policy you want to add it to. I recommend creating a new policy for each printer makes it a l…
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

867 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

22 Experts available now in Live!

Get 1:1 Help Now