Hello. I am using this script.
Under the line
WriteText.WriteLine("Memberships" & vbTab & vbTab & ":" & vbCr)
I want to enumerate all the groups that a user is member of. I think it is possible to do it the same way I did with proxyaddresses, but I can't find the correct value for each "groups" instead of "proxyaddress".
Code:
Dim objFSO, WriteText, strText, strNewText, objFile, objConnection, objCommand, objRecordSet, objUser, strUserDN, strResult, arrProxyAddresses, objMemberOf
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"SELECT Name, sAMAccountName, mail, proxyAddresses, homeDirectory, homeDrive, memberOf, scriptPath, distinguishedName FROM 'LDAP://dc=company,dc=local' WHERE objectCategory='Person'"
Set objRecordSet = objCommand.Execute
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WriteText = objFSO.OpenTextFile("test.txt", 8, true)
objRecordSet.MoveFirst
While Not objRecordSet.EOF
strUserDN = objRecordSet.Fields("distinguishedName")
set objUser = GetObject("LDAP://" & strUserDN)
if objUser.AccountDisabled = FALSE Then
Do Until objRecordSet.EOF
WriteText.WriteLine("Name" & vbTab & vbTab & ":" & objRecordSet.Fields("Name").Value & vbCr)
WriteText.WriteLine("Account" & vbTab & vbTab & ":" & objRecordSet.Fields("sAMAccountName").Value & vbCr)
WriteText.WriteLine("Mail Addresser" & vbTab & ":" & vbCrLf & vbTab & vbTab & objRecordSet.Fields("mail").Value & vbCr)
arrProxyAddresses = objRecordSet.Fields("proxyAddresses")
if isArray(objRecordSet.Fields("proxyAddresses")) Then
strResult = "Proxy Addresses" & vbTab & ":"
For Each ProxyAddress in arrProxyAddresses
WriteText.WriteLine (vbTab & vbTab & ProxyAddress & vbCr)
Next
objRecordSet.MoveNext
End if
WriteText.WriteLine("Memberships" & vbTab & vbTab & ":" & vbCr)
WriteText.WriteLine("Homedir" & vbTab & vbTab & ":" & objRecordSet.Fields("homeDirectory").Value & vbCr)
WriteText.WriteLine("Homedrive" & vbTab & ":" & objRecordSet.Fields("homeDrive").Value & vbCr)
WriteText.WriteLine("Scriptpath" & vbTab & vbTab & ":" & objRecordSet.Fields("scriptPath").Value & vbCrLf)
objRecordSet.MoveNext
Loop
Else
objRecordSet.MoveNext
End if
Wend
WriteText.Close
Set WriteText = NOTHING
Set objFile = objFSO.OpenTextFile("test.txt", 1, true)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "smtp", "")
strNewText = Replace(strNewText, "SMTP", "")
Set objFile = objFSO.OpenTextFile("test.txt", 2, true)
objFile.WriteLine strNewText
objFile.Close
Set objFSO= NOTHING
WScript.Echo "Done"
WriteText.WriteLine("Memberships" & vbTab & vbTab & ":" & vbCr)
I want to enumerate all the groups that a user is member of. I think it is possible to do it the same way I did with proxyaddresses, but I can't find the correct value for each "groups" instead of "proxyaddress".