Welcome to Powergui.org - an open source community for Windows Powershell

PowerGUI.org PowerGUI.org and blogs

Forums » Active Directory and PowerShell

Thread: memberships of all users in an ou

This question is answered.


Permlink Replies: 2 - Pages: 1 - Last Post: Nov 30, 2009 1:21 PM by: Jon Reider
Jon Reider

Posts: 31
Registered: 3/16/09
memberships of all users in an ou
Posted: Nov 25, 2009 12:56 PM
 
  Click to reply to this thread Reply


I have a script that will list all users memberships in an OU, but I don't know what user belongs to what groups. My list looks like:

I would like these groups to be separated by each user.

Name

----

126_MyLeads_Email

Cancun 2009

126_ShipNotify

126_Supports

126_SalesActivity

126_Arkoma

126

126_MyLeads_Email

Cancun 2009

Reps - Domestic - Principals

Reps - Bryan - Principals

Incentive Trip - March

126_ShipNotify

126_SalesActivity

126_Arkoma

126

Reps - West - Principals

126_Principals

126_MyLeads_Email

126_ShipNotify

126_Supports

126_SalesActivity

126_Arkoma

126

126_MyLeads_Email

Cancun 2009

126_InternationalShipping

126_SalesOrderAcknowledgement

126_ShipNotify

Repnet Testers

126_Supports

126_SalesActivity

126_Arkoma

126

PlayCADusers





$RepNo = Read-Host -Prompt "Enter Rep Number"

# Looks for any OU with the name you put in the prompt

$RepName = get-qadobject -Type OrganizationalUnit | select Name | Where-Object {$_.Name -like "$RepNo*"}

# Cleans up the name attribute so it can be used as an OU.

$RepNamefix = $RepName -replace "@{Name=","" -replace "}",""

# Puts the name in OU format

$RepOU = "ou=" + $RepNamefix + ",ou=reps,dc=playlsi,dc=com"

# Gets all users in an OU

$User = Get-QADUser -SearchRoot $RepOU -SearchScope OneLevel

ForEach ($members in $user){

$members.memberOf | Get-QADGroup | sort

}




seaJhawk


Posts: 414
Registered: 12/15/08
Re: memberships of all users in an ou
Posted: Nov 30, 2009 12:45 PM   in response to: Jon Reider
Answered
  Click to reply to this thread Reply

Hi John,
If I understand you correctly, I think you can get what you want by changing your last foreach statement to this:

ForEach ($members in $user){

$members.Name

"-----------------"

$members.memberOf | Get-QADGroup | sort | foreach{$_.name}

""

}



It will print the user's name followed by some dashes, followed by the names of the groups that the user is a member of.

-Chris



Jon Reider

Posts: 31
Registered: 3/16/09
Re: memberships of all users in an ou
Posted: Nov 30, 2009 1:21 PM   in response to: seaJhawk
 
  Click to reply to this thread Reply

Perfect and simple.

Thanks again SeaJhawk.



Legend
MVP: 2501 + pts
Guru: 2001 - 2500 pts
Expert: 751 - 2000 pts
Enthusiast: 31 - 750 pts
Novice: 0 - 30 pts
Moderators
Helpful answer (5 pts)
Answered (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums