Solved

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

Posted on 2013-12-02
4
666 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
[X]
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
  • 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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
A brief introduction to what I consider to be the best editor for PowerShell.
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

688 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