title: Powershell AD user search by name and OU
body: <p>I receive task on studies to create command that will find a specific users in specific <code>OU</code> in Active Directory.</p>
  
  <p>More precise, find all persons that name is <code>A*</code> and are located in <code>OU</code> <code>*es</code>.</p>
  
  <p>After hours of researching I created such commands: </p>
  
  <p>For finding all <code>A*</code> users:</p>
  
  <pre><code>Get-ADUser -filter {name -like "A*"}
  </code></pre>
  
  <p>For finding all <code>*es</code> <code>OU</code></p>
  
  <pre><code>Get-ADObject -filter {OU -like "*es"}
  </code></pre>
  
  <p>And I don't have idea how to connect those outputs.</p>
  
  <p>I was thinking about such resolutions, but they don't work for me.</p>
  
  <pre><code>$var = Get-ADObject -filter {OU -like "*es"} | Select DistinguishedName
  Get-ADUser -filter {name -like "A*"} -SearchBase $var
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>Get-ADUser -filter {name -like "A*" -and OU -like "*es"}
  </code></pre>
  
  <p>I'm lost, please advice. </p>