Powershell – How to check if a user is in a particular group from a particular OU in Powershell

active-directorypowershell

Here's my question.

I have multiple OUs that represent physical locations so it's structured like this.

COMPANY.COM\LOC1\Users (user1, user2, user3 etc…)
COMPANY.COM\LOC2\Users (user4, user5, user6 etc…)

Each location has a group that the user should be a part of and I need to audit to make sure users are a part of that group.

OU LOC1, I need to make sure all users (user1, user2, user3) in OU LOC1 are a part of security group LOC1_GRP and output the ones that aren't.

Best Answer

what about Get-QADUser? You can filter all users for example not belonging to a specific group like this:

get-qaduser -searchroot 'company.com/LOC1/Users' | ? {[string]$_.memberof -notmatch 'LOC1_GRP'}
Related Topic