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"
}
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"
}
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.
ASKER
For any ID it gives the same result... Even if the user is not a part of that group
ASKER
Any other script I can try
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 :)
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 :)
ASKER
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 :)
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 :)