Solved

Export Group in AD with Users in it

Posted on 2014-01-17
13
229 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
  • 7
  • 6
13 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 11

Author Comment

by:Ackles
Comment Utility
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
Comment Utility
First code should do it.. The output will look like..Example..
0
 
LVL 11

Author Comment

by:Ackles
Comment Utility
The first code only gives one user per group.
Second code just makes new row for every user.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 40

Expert Comment

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

Author Comment

by:Ackles
Comment Utility
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
Comment Utility
Yes it can be done... in line 5 change -join "`n" to -join ","
0
 
LVL 11

Author Comment

by:Ackles
Comment Utility
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
Comment Utility
yes..
0
 
LVL 11

Author Comment

by:Ackles
Comment Utility
Great Thanks a bunch!!!
A
0
 
LVL 11

Author Closing Comment

by:Ackles
Comment Utility
Perfect!!!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
A procedure for exporting installed hotfix details of remote computers using powershell
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

6 Experts available now in Live!

Get 1:1 Help Now