digitalhitman00
asked on
AD Powershell query for Users and Groups
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Get-ADUser -properties memberof | where {$_.memberof -notcontains "*groupname*"}