[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2013-12-02
4
Medium Priority
?
682 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 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

650 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