Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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, mail, 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:\domainusers.csv", 8, True)
- logStream.writeline("Name,Email,Profile Path,Home Drive,Account Disabled,Password Required,User Changable Password,Password Expires,SmartCard Required,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
- If objRecordset.Fields("userAccountControl").Value AND ADS_UF_SMARTCARD_REQUIRED Then
- Text = Text & ",Yes"
- Else
- Text = Text & ",No"
- End If
- logStream.writeline(objRecordset.Fields("Name").Value & ","_
- & objRecordset.Fields("mail").Value & ","_
- & objRecordset.Fields("profilePath").Value & ","_
- & objRecordset.Fields("homeDrive").Value & ","_
- & text & ","_
- & objUser.logonCount & ","_
- & objUser.LastLogin & ","_
- & objUser.PasswordLastChanged & ","_
- & objUser.whenCreated & ","_
- & objUser.whenChanged & ","_
- )
- objRecordSet.MoveNext
- Loop
- logStream.Close
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement