Link to home
Start Free TrialLog in
Avatar of Pavan Joshi
Pavan Joshi

asked on

Ad group Member validation

Wanted to check if user is a part of an AD group
Script should help to get info for multiple users at once

Below script is not working as its shows do not exists even if the user is a part of the group:

$user = "xxxxxx"
$group = "xxxxxxxxxx"
$members = Get-ADGroupMember -Identity $group -Recursive | Select -ExpandProperty Name

If ($members -contains $user) {
      Write-Host "$user exists in the group"
 } Else {
        Write-Host "$user not exists in the group"
}
Avatar of Derek Souter
Derek Souter
Flag of United Kingdom of Great Britain and Northern Ireland image

have you tried simply listing all the members of the group that are returned?    I would suggest that it may be showing username as domain\username - and you are not necessarily checking for that.
Avatar of Pavan Joshi
Pavan Joshi

ASKER

For any ID it gives the same result... Even if the user is not a part of that group
Any other script I can try
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

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
Wow, @Obda
It worked but wanted to know if I can use a file as content where all IDs are present and just run the script
SOLUTION
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
Thanks oBdA
The script works now and I was able to get the output as required.
This is one forum where I get maximum help and I am always thankful to you all :)
Thanks oBdA
The script works now and I was able to get the output as required.
This is one forum where I get maximum help and I am always thankful to you all :)