• Vik Jaswal

Check AD Group Membership using PowerShell

Here is a function which allows you to quickly check the group membership of a particular user. Click here to download the script file.

< #Function to check group membership of the user when “samaccountname” and “groupname” is provided.Returns “True” or “False” #> Function IsMemberOf ($user, $adgroup) {     Import-Module ActiveDirectory     $groupusers = Get-ADGroupMember $adgroup| Select-Object –ExpandProperty` SamAccountName     If ($groupusers -contains $user) {              $True      }     Else { $false       } } #Example IsMemberOf “vik” “PowerUsersGroup”