Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Powershell - export 'member of' for a user

Posted on 2011-09-26
Medium Priority
Last Modified: 2012-05-12

For backup purposes we need an export per user that contains the memberships for that user.

Say for example user "john doe" is in '' in the OU 'users'. Then I would need an export (text or csv, doesn't realy mather) that contains a line-per-line export of all groups that user is member of. (the 'member of' tab in the user properties window)

i would like to do this in powershell (no third party software) because it is part of a bigger script.

thank you!
Question by:ISUNI
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 37

Accepted Solution

Neil Russell earned 2000 total points
ID: 36597692
The easiest way is to install the Quest QAD Commandlets for powershell. This is just a set of commandlets that add on to powershells functionality. After all powershell is basically just an extensible shell.

For a single user use...

$user = Get-QADUser 'Poshoholic'
$user.memberOf | Get-QADGroup

And for ALL users use

$Users = Get-QADUser
foreach ($User in $Users)
Write-Host "------------------------"
$user.memberof | Get-QADGroup  
LVL 37

Expert Comment

by:Neil Russell
ID: 36597979
Sorry, forgot link to powershell extensions by Quest

Expert Comment

ID: 36600884
One additional note: the $User.MemberOf attribute does not contain the default group of the user.  You either need to include the $User.PrimaryGroupId - which is numeric, and equates to the RID of the group.  Digging that out gets complicated considering you can much more easily do...

Get-QADMemberOf 'Poshoholic'

Open in new window

...for a single user, and...

$Users = Get-QADUser
foreach ($User in $Users) {
    Write-Host "------------------------"
    Get-QADMemberOf $User 

Open in new window

Hope that helps!
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

LVL 37

Expert Comment

by:Neil Russell
ID: 36601236
Do YOU actually change users Primary Group? I have not met a sys admin that does that in years! As the Default Default group is Domain Users and EVERY user is a member of it, I never report on it.

Expert Comment

ID: 36601261
Actually, I found this the "hard" way at a customer where they make a practice of setting the default group on service and admin accounts to something other than Domain Users for subsequent processing by Group Policy.

So... yes, I've seen it. In a domain of 18k+ accounts, it matters.

Author Closing Comment

ID: 36954114
Thank you! This helps.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : All lightning effects with instructions : http://www.mediaf…

664 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