Press "Enter" to skip to content

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, "-"
    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
End If


Related Post

Resolve temporary profile issues on RDS / TSE remo... Context For multiple and often unknown reasons, users are connected to their session on a temporary profile. The user does not find his settin...
Active directory: Delete a child domain In the article Active directory: setting up a child domain where I explain how to configure a child domain in an Active Directory environment, I will ...
GPO: Run a script when the computer starts Presentation In this article, we will see how to set up a script that runs at startup of the post using Group Policy (GPO). The advantage of using...
Vbs: IIS log rotation script Unlike linux, Windows does not have a task for log rotation. Below is a Vbs script that allows you to do this rotation. By adapting the sLogFold...
It looks like you're using an adblocker.
We use ads to keep our content free. Please support us by turning off your adblocker.