?
Solved

Export Group in AD with Users in it

Posted on 2014-01-17
13
Medium Priority
?
238 Views
Last Modified: 2014-01-20
Hi,
I want an excel exported from AD for Groups & their respective members.

I don't want to use QAD & the format has to be that One Group per row & all the members in it in the same row but in second column.

Only SamAccountName of user should be there.

Server & Domain is 2008R2

Regards,
A
0
Comment
Question by:Ackles
[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
  • 7
  • 6
13 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 total points
ID: 39788802
You can try this code and see if you get the result in expected format..
Get-ADGroup -Filter * | % {
$members = Get-ADGroupMember $_.DistinguishedName -Recursive | 
	?{$_.objectClass -eq "user"} | 
	Select -ExpandProperty SamAccountName
$_ | Select @{N="GroupName";E={$_.Name}},@{N="members";E={$members -join "`n"}}
}| Export-Csv C:\report.csv -nti

Open in new window


Here is a slightly modified code (Different output format) which will help you to filter through members..
Get-ADGroup -Filter * | % {
$Group = $_.Name
Get-ADGroupMember $_.DistinguishedName -Recursive | 
	?{$_.objectClass -eq "user"} | 
	Select @{N="GroupName";E={$Group}},SamAccountName
}| Export-Csv C:\report.csv -nti

Open in new window

0
 
LVL 11

Author Comment

by:Ackles
ID: 39788815
I know this, please read the question.
I want one row per Group & all the users in the next column but in same row.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39788846
Thats what the first code does.. Did you try it?
If not provide a sample of how it should be, so I can modify the code for you..
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Author Comment

by:Ackles
ID: 39788872
Column A, Row 1 = Group1
Column B, Row 1= Allusers in Group1

Column A, Row2=Group2
Column B, Row2= Allusers in Group2
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39789096
First code should do it.. The output will look like..Example..
0
 
LVL 11

Author Comment

by:Ackles
ID: 39794039
The first code only gives one user per group.
Second code just makes new row for every user.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39794095
Did you try to expand the row as i shown in the screenshot?
0
 
LVL 11

Author Comment

by:Ackles
ID: 39794188
My bad, you are right. It does work.

However, would it be too much to ask if they can be separated by comma?
It's really not readable if you have 100 users in one group & so on....

Please!

A
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39794242
Yes it can be done... in line 5 change -join "`n" to -join ","
0
 
LVL 11

Author Comment

by:Ackles
ID: 39794244
Get-ADGroup -Filter * | % {
$members = Get-ADGroupMember $_.DistinguishedName -Recursive |
      ?{$_.objectClass -eq "user"} |
      Select -ExpandProperty SamAccountName
$_ | Select @{N="GroupName";E={$_.Name}},@{N="members";E={$members -join ","}}
}| Export-Csv C:\report.csv -nti


Like this?
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39794252
yes..
0
 
LVL 11

Author Comment

by:Ackles
ID: 39794271
Great Thanks a bunch!!!
A
0
 
LVL 11

Author Closing Comment

by:Ackles
ID: 39794272
Perfect!!!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

752 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