Link to home
Start Free TrialLog in
Avatar of ndalmolin_13
ndalmolin_13Flag for United States of America

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ndalmolin_13

ASKER

That did it.  Thanks for your help.
Nice!.. If you didn't require any further assistance then don't forget to close the question.. :-)
Thanks for your help.