Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Power Shell - Quest - How to pull all the group membership for multiple users

Posted on 2013-06-12
Medium Priority
Last Modified: 2013-06-12

Any easy way to put a list of sAMAccountNames into a text file and have it output all the group memberships for each account into a .CSV file ?
Question by:MilesLogan
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
  • 3
  • 2
LVL 40

Expert Comment

ID: 39242080
Try this...
GC C:\user.txt | Get-QADUser | %{
	New-Object PSObject -Property @{
	Firstname = $_.Firstname
	Lastname = $_.Lastname
	DisplayName = $_.DisplayName
	Email = $_.Email
	Title = $_.Title
	group = ""
$_.memberof | %{
	New-Object PSObject -Property @{
	Firstname = ""
	Lastname = ""
	DisplayName = ""
	Email = ""
	Title = ""
	group = ($_ -Split ",")[0] -replace "CN="
} | Select Firstname,Lastname,DisplayName,Email,Title,group | Export-Csv C:\report.csv -NoTypeInformation

Open in new window

Ref : http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_28085213.html

Author Comment

ID: 39242330
Hi SubSun

It works perfect ! I tried to modify it so it also pulls the account description but it did not work .. can you give me a hit ?

I added the two lines below but it did not output it .

description = $_.description
Description = ""
LVL 40

Accepted Solution

Subsun earned 2000 total points
ID: 39242350
I guess you didn't select the description property..
Change last line to..
} | Select Firstname,Lastname,DisplayName,Email,Title,description,group | Export-Csv C:\report.csv -NoTypeInformation

Open in new window


Author Closing Comment

ID: 39242431
Awesome as always !

Thank you so much again !
LVL 40

Expert Comment

ID: 39242445
You are welcome, I'm glad I was able to help... :-)

Featured Post

Does Powershell have you tied up in knots?

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
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 …

618 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