title: vbscript: LDAP custom filter queries trying to search for all computers in the domain but excluding an OU or 2
body: <p>When I run:</p>
  
  <pre><code>Set objConnection = CreateObject("ADODB.Connection")
  Set objCommand =   CreateObject("ADODB.Command")
  objConnection.Provider = "ADsDSOObject"
  objConnection.Open "Active Directory Provider"
  
  strFilter = "(&amp;(objectClass=computer))"
  
  strAttributes = "name,distinguishedName"
  
  strQuery = strDomainDN &amp; ";" &amp; strFilter &amp; ";" &amp; strAttributes &amp; ";subtree"
  
  Set objCOmmand.ActiveConnection = objConnection
  objCommand.CommandText = strQuery
  objCommand.Properties("Page Size") = 9999
  Set objRecordSet = objCommand.Execute
  objRecordSet.MoveFirst
  
  Do Until objRecordSet.EOF
      strADObjects = strADObjects &amp; objRecordSet.Fields("Name").Value &amp; vbCrLf
      'Wscript.Echo "Location: " &amp; objRecordSet.Fields("DistinguishedName").Value
      objRecordSet.MoveNext
  Loop
  </code></pre>
  
  <p>my query works like a champ but when i try to filter out a specific OU, the script either throws an error or excludes nothing at all.  I've tried many different variants inside of strFilter.  Is there a way you can query an entire domain for all computers but excluding the results from a particular OU?  ...or OUs???  I've tried:</p>
  
  <pre><code>strFilter = "(&amp;(objectClass=computer) (!(distinguishedName=*,OU=Computers,DC=mydomain,DC=myTLD)))"
  strFilter = "(&amp;(objectClass=computer) (!distinguishedName=*,OU=Computers,DC=mydomain,DC=myTLD))"
  strFilter = "(&amp;(objectClass=computer) (!(OU=Computers,DC=mydomain,DC=myTLD)))"
  strFilter = "(&amp;(objectClass=computer) (!OU=Computers,DC=mydomain,DC=myTLD))"
  </code></pre>
  
  <p>can anyone offer any pointers to where I might be messing this up?  TIA~!</p>
  
  <p>Edit:  Also found and tried but no worky:</p>
  
  <pre><code>(&amp;(!(ou:dn:=Computers))(objectClass=Computer))
  </code></pre>