title: LDAP userAccountControl atttribute
body: <p>In <code>PowerShell</code> I use the following <code>LDAP query</code> to retrieve the active directory properties of a host name:</p>
  
  <pre><code>$Filter = "(&amp;(ObjectCategory=Computer)(ObjectClass=Computer)(CN=$ComputerName))"
  if ($Found = ([ADSISEARCHER]$Filter).FindOne()) {
      $Details = $Found.GetDirectoryEntry()
  }
  </code></pre>
  
  <p>Once I have these properties I would like to check if the computer account is disabled. The following <code>LDAP query</code> is allowing me to do that:</p>
  
  <pre><code>$Filter = "(&amp;(objectCategory=computer)(userAccountControl:1.2.840.113556.1.4.803:=2)(CN=$ComputerName))"
  ([ADSISEARCHER]$Filter).FindOne()
  </code></pre>
  
  <p>What I would like to know is, how can I avoid using the second <code>LDAP query</code> and use the variable <code>$Details</code> from the first <code>LDAP query</code> to obtain <code>$True</code> or <code>$False</code> if the computer account is disabled?</p>
  
  <p>I found some <a href="https://knowledge.zomers.eu/PowerShell/Pages/How-to-control-UserAccountControl-Active-Directory-flags-with-PowerShell.aspx" rel="nofollow">extra information</a> but I can't seem to put the pieces together. </p>
  
  <p>Thank you for your help.</p>