VBScript to Get Domain Groups for Current User

This take me back a bit…

[sourcecode language="vb"]
Option Explicit

' Get the current user's domain and username.
Dim wsxNetwork
Set wsxNetwork = CreateObject("WScript.Network")

Dim sDomain, sUser
sDomain = wsxNetwork.UserDomain
sUser = wsxNetwork.UserName

' Get the user.
Dim objUser
Set objUser = GetObject("WinNT://" & sDomain & "/" & sUser)

' We'll build a list of group names.
Dim sGroupNames

' For each of the groups for the user...
Dim objGroup
For Each objGroup In objUser.Groups

    ' Add the group name to the string.
    sGroupNames = sGroupNames & objGroup.Name & vbCrLf

Next

' Show the list of groups.
MsgBox sGroupNames
[/sourcecode]
Be Sociable, Share!
This entry was posted in VBScript. Bookmark the permalink.

Leave a Reply

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