Active Directory Export Script

Posted on 2010-09-14
Last Modified: 2012-05-10
I need to export the name of each OU, Security Group and Distribution Groups along with their members names to a text file.  Our domain name is FSS.local and our DC is FSSFS.  Does anyone have a clue how to do this?
Question by:steveLaMi

Expert Comment

ID: 33673789
at the command line

net users /domain
will get you a list of users

net groups /domain
will get you a list of groups

you can direct them into a text file like this
net users /domain>USERS.TEXT
net groups /domain>>USERS.TEXT

Expert Comment

ID: 33673978
For security group membership, create a batch file that reads:
cscript listgroup.vbs>grouplist.txt

Create a vbs file named "listgroup.vbs" containing:

On Error Resume Next
Set objGroup = GetObject _
  ("LDAP://cn=<groupname>;ou=<path to group>;dc=FSS,dc=local")
arrMemberOf = objGroup.GetEx("member")
WScript.Echo "<groupname>"
For Each strMember in arrMemberOf
  WScript.echo strMember

This will create a file named whatever you put in place of <groupname>. You'd have to do this with each security group or distribution list.

Author Comment

ID: 33673995
Is there a way to get the users of a distribution group into a text file?
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

LVL 57

Expert Comment

by:Mike Kline
ID: 33673996
I would suggest something like adfind or powershell.  Michael Smith has a good overview of doing this with adfind
In addition to that if you want to export the OUs and their names
adfind -default -f objectcategory=organizationalunit name

Author Comment

ID: 33674005
Matt... I didnt see your answer before I posted my last comment, I will give it a try
LVL 17

Accepted Solution

Tony Massa earned 500 total points
ID: 33674190
Here's a script that will prompt for the DNS domain name, and group name, then put the user info into an Excel spreadsheet.  Note:  Assumes you have Excel installed on the computer you're running it on.

Expert Comment

ID: 33675267
Here is another script which you can use to get all groups and group member details:

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

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 article outlines the process to identify and resolve account lockout in an Active Directory environment.
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 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