Vbs: Check if a user is part of a group

The function below is used to check if a user is part of an AD group.

The function returns True or False.

' *****************************************************
'This function checks to see if the passed group name contains the current
' user as a member. Returns True or False
Function IsMember(groupName)
    If IsEmpty(groupListD) then
        Set groupListD = CreateObject("Scripting.Dictionary")
        groupListD.CompareMode = 1
        ADSPath = EnvString("userdomain") & "/" & EnvString("username")
        Set userPath = GetObject("WinNT://" & ADSPath & ",user")
        For Each listGroup in userPath.Groups
            groupListD.Add listGroup.Name, "-"
        Next
    End if
    IsMember = CBool(groupListD.Exists(groupName))
End Function
' *****************************************************
 
' *****************************************************
'This function returns a particular environment variable's value.
' for example, if you use EnvString("username"), it would return
' the value of %username%.
Function EnvString(variable)
    variable = "%" & variable & "%"
    EnvString = oShell.ExpandEnvironmentStrings(variable)
End Function
' *****************************************************

PS: pour fonctionner la fonction IsMember à besoin de la fonction EnvString(variable)

Use :

If isMember("GROUP_NAME") Then
  **Action**
End If

 



Related Posts


GPO: Make users administrator of their post
Presentation In this tutorial, we are going to have how to set up a GPO to make the admin domain users of their post. The goal is to add the Domain Users group in the Administrators 1 group of the user station. The Domain Admins group is already a me

Exchange 2016: Installation and Configuration
In this tutorial, we will see how to install and configure Exchange 2016. Exchange is a mail server designed by Microsoft, it is the professional version of Hotmail (Outlook). Environment An Active Directory domain. A Windows Server 2016 server that

Active directory: How to set up a child domain
In this tutorial, we will see how to put a child domain in an Active Directory tree. A child domain is a subdomain of one of the component domains in your Active Directory forest. Subdomain segmentation allows logical partitioning of the Active Direc