Roberto Alves

Scripting and server based computing

.VBS that verify if a user belongs to a group

This script can be included in others scripts to verify if a user belongs to a specific group.

Set oShell = CreateObject(“Wscript.Shell”)
Set oNet = CreateObject(“Wscript.Network”)
set oFSO = CreateObject(“Scripting.FileSystemObject”)

domain = “dominio”
teste=ismember(“Domain UsErs”)
msgbox teste
Function IsMember(sGroup)
Dim sAdsPath, oUser, oGroup
If IsEmpty(oGroupDict) Then
Set oGroupDict = CreateObject(“Scripting.Dictionary”)
oGroupDict.CompareMode = vbTextCompare
sAdsPath = oNet.UserDomain & “/” & oNet.UserName
Set oUser = GetObject(“WinNT://” & domain & “,user”)
For Each oGroup In oUser.Groups
oGroupDict.Add oGroup.Name, “-”
Set oUser = Nothing
End If
IsMember = CBool(oGroupDict.Exists(sGroup))
End Function

Category: Scripts

Your email address will not be published. Required fields are marked *