I am looking to create a script which will only show users in an OU who are members of "non-standard" groups.
For example, all users in the "Accounting" OU will be members of at least one group with "Accounting" in its name. Example: "XYZ-Accounting-Global". This is our standard group naming. Those users with only "Accounting" group memberships can be skipped.
I would like to target only those users in the OU which are members of any non-standard group for that OU.
- Example: User is in the "Accounting" OU, and is a member of "XYZ-Accounting-Global", BUT is also a member of "XYZ-Payroll-Global".
So far, I have come up with this:
$domain = "DC=company,DC=com"
$dept = read-host "What is the DEPT. name?"
Get-ADuser -SearchBase "OU=$dept,OU=Users,OU=company,$domain" -Filter * -properties memberof | Where-Object {!($_.memberof -like "*$dept*")}
This isn't working correctly though. It seems to be returning those users who are not members of a group with the $dept
name in it. Unfortunately, I do not know how to fix this.
Any help is appreciated. Thank you.