Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

List all AD users with memberof

$
0
0

Hi I have got this script and it works fine, but I cant add the memberof groups for each user. 

On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Const ADS_UF_ACCOUNTDISABLE = &H0002
Const ADS_UF_PASSWD_NOTREQD = &H0020
Const ADS_UF_PASSWD_CANT_CHANGE = &H0040
Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
Const ADS_UF_SMARTCARD_REQUIRED = &H40000
'Set RootDSE
Set objRootDSE = GetObject("LDAP://rootDSE")
strDomain = objRootDSE.Get("defaultNamingContext")
strADPath = "LDAP://" & strDomain
'wscript.Echo strADPath
Set objDomain = GetObject(strADPath)
'wscript.echo "objDomain: " & objDomain.distinguishedName
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "SAURON"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _"SELECT Name, description, sAMAccountName, st, postalCode, co, l, profilePath, homeDrive, distinguishedName,userAccountControl FROM '"& strADPath &"' WHERE objectCategory='user'"  
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Set objFSO = CreateObject("scripting.filesystemobject")
Set logStream = objFSO.opentextfile("C:users\dom.adm.pa\desktop\domainusers.csv", 8, True)
logStream.writeline("Name,Description,sAMAccountName,st,postalCode,co,l,Account Disabled,Password Required,User Changable Password,Password Expires,Login Count,Last Login,Last Password Change,Created,Modified")
Do Until objRecordSet.EOF
        strDN = objRecordset.Fields("distinguishedName").Value
        Set objUser = GetObject ("LDAP://" & strDN)
        If objRecordset.Fields("userAccountControl").Value AND ADS_UF_ACCOUNTDISABLE Then
                Text = "Yes"
        Else
                Text = "No"
        End If
        If objRecordset.Fields("userAccountControl").Value AND ADS_UF_PASSWD_NOTREQD Then
                Text = Text & ",No"
        Else
                Text = Text & ",Yes"
        End If
        If objRecordset.Fields("userAccountControl").Value AND ADS_PASSWORD_CANT_CHANGE Then
                Text = Text & ",No"
        Else
                Text = Text & ",Yes"
        End If   
        If objRecordset.Fields("userAccountControl").Value AND ADS_UF_DONT_EXPIRE_PASSWD Then
                Text = Text & ",No"
        Else
                Text = Text & ",Yes"
        End If


       
        logStream.writeline(objRecordset.Fields("Name").Value & ","_& objRecordset.Fields("description").Value & ","_& objRecordset.Fields("sAMAccountName").Value & ","_& objRecordset.Fields("st").Value & ","_& objRecordset.Fields("postalCode").Value & ","_& objRecordset.Fields("co").Value & ","_& objRecordset.Fields("l").Value & ","_	& objUser.logonCount & ","_& objUser.LastLogin & ","_& objUser.PasswordLastChanged & ","_& objUser.whenCreated & ","_& objUser.whenChanged & ","_   
		)         
Loop
logStream.Close



Viewing all articles
Browse latest Browse all 15028

Trending Articles