title: Powershell Get-ADUser and variables
body: <p>I am trying to write a Powershell script that will allow me to query the <code>samaccountname</code> and other fields from a list of e-mail addresses. (reverse lookup)</p>
  
  <p>My email.csv file has a users header, followed by the list of e-mail addresses.</p>
  
  <p>What am I doing wrong?</p>
  
  <pre><code>$users = Get-Content .\email.csv
  $users | ForEach-Object {
  Get-ADUser -LDAPFilter "(emailaddress=$users)" -Properties samaccountname | Select-Object -Property samaccountname
  } | Export-Csv -Path .\emailexport.csv 
  </code></pre>