troubleshooting Question

AD Powershell query for Users and Groups

Avatar of digitalhitman00
digitalhitman00 asked on
Active DirectoryPowershell
2 Comments1 Solution565 ViewsLast Modified:
I have a script that is running two commands, 1. get the AD Group and 2. List the users who are not in that AD group.  This works fine. What I need to do is expand my AD Groups variable to hold multiple Groups and 2. List the users who do not fall in any of those AD Groups.

1. $groups = Get-ADGroup -Filter { Name -like "*groupname*"}     <-- that will hold multiple groups in the $groups variable.
2. Get-ADUser -filter {memberof -notlike $groups}  <--This doesnt work as is, but the logic is to list the users that do not fall in any of those groups.

whats the correct way, efficient way of doing this?  I have tons of groups setup in a specific naming convention where I can filter with a wildcard and pull all the groups I need.  I just need to compare each user to see if they fall in any one of those groups. If they do not fall into any of the groups then list the user.
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros