Powershell Script to connect AD and check if the user is member of a group or not from client

Fahad Noaman 171 Reputation points
2021-04-12T09:59:18.44+00:00

Can you help me to create a Powershell Script to connect AD and check if the user is member of a group or not from client machine and set a registery key based on the condition

Windows for business Windows Server User experience PowerShell
Windows for business Windows Server User experience Other
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2021-04-13T04:55:27.213+00:00

    Hi,

    The PowerShell AD module has to be installed first.
    https://4sysops.com/wiki/how-to-install-the-powershell-active-directory-module/

    Then you check the user like this

    $username = 'user1'  
    $group = 'group1'  
    $user = Get-ADGroupMember -Identity $group | Where-Object {$_.name -eq $username}  
    if($user){  
        Write-Host 'member found'  
    }  
    else{  
        Write-Host 'member not found'  
    }  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    3 people found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.