title: Piping output of get-ADUser to Get-ADGroup with an LDAP filter
body: <p>I'm trying to stitch together two lines of PowerShell, but I just can't figure the syntax. There is <a href="https://stackoverflow.com/questions/34550868/combine-get-adgroup-and-get-aduser-results">a post</a> that sounds like it might be what I need,  but it isn't using <code>-LDAPFilter</code>.</p>
  
  <p>To generate a list of AD users created in the last 100 days, I use</p>
  
  <pre><code>$now = ((Get-Date).AddDays(-100)).Date
  $users = Get-ADUser -Filter {whenCreated -ge $now} -Searchbase "OU=staff,OU=SMUC_Users,DC=stmarys,DC=ac,DC=ie" |
           Where-Object { $_.Enabled -eq 'True' }
  </code></pre>
  
  <p>And this code from <a href="https://stackoverflow.com/questions/23552094/how-to-get-all-ad-user-groups-recursively-with-powershell-or-other-tools?noredirect=1&amp;lq=1">"How to get ALL AD user groups (recursively) with Powershell or other tools?"</a> does the next step, which is to find all the groups that a user is a member of:</p>
  
  <pre><code>$username = 'd.trump'
  $dn = (Get-ADUser $username).DistinguishedName
  Get-ADGroup -LDAPFilter ("(member:1.2.840.113556.1.4.1941:={0})" -f $dn) |
      select -Expand Name 
  </code></pre>
  
  <p>but I can't pipe the output of the first into the second to get an overall list.</p>
  
  <pre><code>Get-ADUser -Filter {whenCreated -ge $now} -Searchbase "OU=staff,OU=SMUC_Users,DC=stmarys,DC=ac,DC=ie" |
      Where-Object { $_.Enabled -eq 'True' } |
      Select-Object DistinguishedName |
      Get-ADGroup -LDAPFilter ("(member:1.2.840.113556.1.4.1941:={0})" -f $_) |
      select -expand Name
  </code></pre>
  
  <p>The error message is:</p>
  
  <blockquote>
    <p>Get-ADGroup : The search filter cannot be recognized</p>
  </blockquote>
  
  <p>I thought the second code snippet extracted the distingushed name and supplied it to the filter, and that is what I have tried to do in the pipeline.</p>