title: Return manager's samacountname for users
body: <p>I've got a requirement to create a CSV file of all active users from AD including the line manager attribute, however I need the line managers <code>sAMAccountName</code>, not the <code>cn</code>.  Here is what I have so far:</p>
  
  
  
  <pre class="lang-psh prettyprint-override"><code>Get-ADUser -server server_ip -Filter { mail -like "*" -and ObjectClass -eq "user" } `
    -SearchBase "OU=Active Users,DC=eu,DC=ad,DC=some_company,DC=com" `
    -Properties objectGUID,displayName,office,division,department,employeeNumber,
      employeeID,mobilePhone,officePhone,ipphone,title,givenName,surname,mail,
      manager,sAMAccountName |
    Export-CSV "EU_AD_Properties.csv"
  </code></pre>
  
  <p>This returns all the data I want, but gives me the line manager's <code>cn</code>, not the <code>samacountname</code>.</p>
  
  <p>Any ideas?</p>
  
  <p>I've tried this:</p>
  
  <pre class="lang-psh prettyprint-override"><code>Get-ADUser -server server_ip -Filter { mail -like "*" -and ObjectClass -eq "user" } `
    -SearchBase "OU=Active Users,DC=eu,DC=ad,DC=some_company,DC=com" `
    -Properties objectGUID,displayName,office,division,department,employeeNumber,
      employeeID,mobilePhone,officePhone,ipphone,title,givenName,surname,mail,
      @{Label="Manager";Expression={(Get-aduser -filter {sAMAccountName -eq $_.Manager}.sAMAaccountName)}},
      sAMAccountName |
    Export-CSV "EU_AD_Properties.csv"
  </code></pre>
  
  <p>However this errors out.</p>