title: Enumerate all users including SIDs
body: <p>I have written a VBScript to list all the users and selected info from AD.  But I would like to add SIDs to the list of user info without having to connect to each user object.  Any ideas?</p>
  
  <pre><code>' Set up the connection to the domain
  Set objConnection = CreateObject( "ADODB.Connection" )
  Set objCommand = CreateObject("ADODB.Command")
  objConnection.Provider = "ADsDSOObject"
  objConnection.Open "Active Directory Provider"
  Set objCommand.ActiveConnection = objConnection
  
  ' Configure the Active Direcctory connection
  objCommand.Properties("Page Size") = 1000
  objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
  
  ' Filter to search AD with
  strFilter = "(&amp;(objectCategory=person)(objectClass=user))"
  
  ' Attributes to return with the search
  strAttrib = "sAMAccountName,cn,sn,givenName,title,department,company,physicalDeliveryOfficeName,mail,telephoneNumber,l,st,postalCode,co,whenCreated,whenChanged,manager,userAccountControl,objectSid"
  
  ' Build the AD query
  strQuery = "&lt;LDAP://dc=yourdomain,dc=com&gt;;" &amp; strFilter &amp; ";" &amp; strAttrib &amp; ";subtree"
  
  ' Create the file system object
  Set objFSO = CreateObject( "Scripting.FileSystemObject" )
  Set objFile = objFSO.CreateTextFile( "users.csv" )
  objFile.WriteLine """Domain"",""User ID"",""CN"",""Last Name"",""First Name"",""Email"",""SID"""
  
  ' Execute the query
  objCommand.CommandText = strQuery
  Set objRecordSet = objCommand.Execute
  
  Do Until objRecordSet.EOF
      objFile.WriteLine objRecordSet.Fields( "objectSid" ).Value
  Loop
  </code></pre>
  
  <p>Unfortunately this returns nothing.</p>