AntiMalware Status

Check if user is member of the group

Here is another quick PowerShell script to check if user is a member of given group.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Clear-Host
if (Get-Module -ListAvailable -Name ActiveDirectory) {
Import-Module ActiveDirectory
} else {
''
Write-Host "Operation aborted. No Active Directory Module found. Run this tool on a Domain Controller." -ForegroundColor Red
''
throw "Error"
}
Write-Host "CHECK IF USER IS MEMBER OF THE GROUP" -ForegroundColor white -BackgroundColor Red
Write-Host
$user = Read-Host [=> "Enter User Name"
$group = Read-Host [=> "Enter Group Name"
$members = Get-ADGroupMember -Identity $group -Recursive | Select -ExpandProperty Name</code>

If ($members -contains $user) {
Write-Host "$user exists in the group"
} Else {
Write-Host "$user does not exist in the group"
}

Another quick idea , please test before you try in live environment ..

Leave a Reply