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
Solved

Help getting an expanded list of users in a group with Powershell

Posted on 2013-12-02
4
660 Views
Last Modified: 2013-12-02
Hello Powershell Experts,

I would like to see a list of all users that are in our various sales groups.  This part is easy enough.  I used the following Powershell code to generate this list.

$SalesGroups = Get-ADGroup –filter  ‘name –eq “Sales*”’
Foreach ($SalesGroup in $SalesGroups) {
      Get-ADGroupMember  -identity $SalesGroup  | Select name, objectclass
}

This produces a list of group members and lets me know whether each group member is an actual user or a group.  

Name                              Objectclass
BobS                              user
LindaQ                              user
PhxTeam                        group
PeteH                              user

Now I want to go through this list and if a group member’s object class equals user, I want to add their name to a variable or array.  If the group member’s object class equals group, I want to get a list of users in that group and add them to the variable or array.  I’m hoping someone can help me with this part.

Thanks,
Nick
0
Comment
Question by:ndalmolin_13
  • 2
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 39690144
Are you trying to get the recursive group membership? If yes you can try..
$SalesGroups = Get-ADGroup –filter  ‘name –eq “Sales*”’
Foreach ($SalesGroup in $SalesGroups) {
  Get-ADGroupMember -identity $SalesGroup -Recursive  | Select @{N="Group";E={$SalesGroup.Name}},name,objectclass
}

Open in new window

0
 
LVL 1

Author Comment

by:ndalmolin_13
ID: 39690283
That did it.  Thanks for your help.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39690497
Nice!.. If you didn't require any further assistance then don't forget to close the question.. :-)
0
 
LVL 1

Author Closing Comment

by:ndalmolin_13
ID: 39691635
Thanks for your help.
0

Featured Post

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.

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

790 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