Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I managed to write the VBScript which does what I wanted, so I will share it here. The script probably needs a very good cleanup, but for now it does the job so I'm hoping it can help other people too.</p> <pre><code>' Get OU strOU1 = "OU=here,DC=mydomain,DC=com" strOU2 = "OU=there,DC=yourdomain,DC=com" Dim samid Dim ldap_command ' Create connection to AD ' Set objConnection = CreateObject("ADODB.Connection") objConnection.Open "Provider=ADsDSOObject;" ' Create command ' Set objCommand1 = CreateObject("ADODB.Command") objCommand1.ActiveConnection = objConnection objCommand1.Properties("Page Size") = 1000 ' Execute command to get all users in OU ' objCommand1.CommandText = _ "&lt;LDAP://" &amp; strOU1 &amp; "&gt;;" &amp; _ "(&amp;(objectclass=user)(objectcategory=person));" &amp; _ "adspath,distinguishedname,sAMAccountName;subtree" Set objRecordSet = objCommand1.Execute ' Show info for each user in OU ' Do Until objRecordSet.EOF ' Show required info for a user ' samid = objRecordSet.Fields("sAMAccountName").Value WScript.Echo "Processing " &amp; objRecordSet.Fields("sAMAccountName").Value Set objCommand2 = CreateObject("ADODB.Command") ldap_command = _ "&lt;LDAP://" &amp; strOU2 &amp; "&gt;;" &amp; _ "(&amp;(objectclass=user)(objectcategory=person)" &amp; _ "(sAMAccountName=" &amp; samid &amp; "));" &amp; _ "adspath,distinguishedname,sAMAccountName;subtree" objCommand2.CommandText = ldap_command objCommand2.ActiveConnection = objConnection objCommand2.Properties("Chase referrals") = &amp;H40 Set objRecordSet2 = objCommand2.Execute If objRecordSet2.RecordCount = 0 Then Wscript.Echo "The sAMAccountName is not in use." Else Wscript.Echo "This ID is in use" End If ' Move to the next user ' objRecordSet.MoveNext Loop </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload