-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMSAD Groups per User.vbs
71 lines (58 loc) · 2.15 KB
/
MSAD Groups per User.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
' Name : distributiongroupswithmanager.vbs
' Description : script to enumerate all distributiongroups with manager
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 01-02-2010
' Level : intermediate
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"
sUID = InputBox("Enter Username")
'strFilter = "(&(objectCategory=group)(mail=*))"
strFilter = "(&(samaccountname=" & sUID & "))"
strAttributes = "distinguishedName"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set objRecordset = adoCommand.Execute
sTemp = "User Name" & vbTab & "Group" & vbCrLf
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
On Error Resume Next
Set objUser = GetObject("LDAP://" & objRecordSet.Fields("distinguishedName").Value)
sTemp2 = objUser.DisplayName & vbCrLf
arrGroups = objUser.memberof
If IsNull(arrGroups) Then
Wscript.Echo "Nothing found"
sTemp2 = sTemp2 & vbTab & "(no groups)" & vbCrLf
'sTemp2 = sGroup & vbCrLf
Else
For Each a In arrGroups
a = Mid(a, 4)
a = Left(a, InStr(1, a, ",", 1) - 1)
'a = Replace(a, "\,", ",")
sTemp2 = sTemp2 & vbTab & a & vbCrLf
'Wscript.Echo objUser.DisplayName & " ; " & objUser.Mail & " ; " & a
Next
End If
'Wscript.Echo objGroup.DisplayName & " ; " & objGroup.Mail & " ; " & objGroup.managedBy
sTemp = sTemp & sTemp2
Set objGroup = Nothing
objRecordSet.MoveNext
Loop
Set objFile = objFSO.CreateTextFile("C:\AAWork\DWADInfo_User.txt", True)
objFile.WriteLine(sTemp)
objFile.Close
CreateObject("WScript.Shell").Run("Excel c:\aawork\dwadinfo_user.txt")
Set objRecordset = Nothing
Set objRootDSE = Nothing
Set adoConnection = Nothing
Set adoCommand = Nothing