INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Powershell return samaccountname for manager in csv output

Powershell return samaccountname for manager in csv output

Powershell return samaccountname for manager in csv output

(OP)
I'm a complete noob when it comes to powershell. 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 sAMAccountName not the cn. Here is what I have so far:

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"

This returns all the data I want but gives me the line managers cn not the samacountname.

Any ideas?

I've tried this:
Get-ADUser -Server IP -Filter {mail -like "*"} -Properties * -SearchBase "OU=Active Users,DC=eu,DC=ad,DC=some_company,DC=com" | select objectGUID, displayName, office, division, department, employeeNumber, employeeID, mobilePhone, officePhone, ipphone, title, givenName, surname, mail, @{Name='Manager';Expression={(Get-ADUser $_.Manager).sAMAaccountName}}, sAMAccountName | Export-CSV "EU_AD_Properties.csv"

But it returns the following error:

Get-ADUser : The server has returned the following error: invalid enumeration context.
At E:\_AxiosSoftware\CUG\eu_ad_export.ps1:2 char:11
+ Get-ADUser <<<< -Server IP -Filter {mail -like "*"} -Properties * -SearchBase "OU=Active Users,DC=eu,DC=ad,DC=some_company,DC=com" | select objectGUID, displayName, office, division, department, employeeNumber, employeeID, mobilePhone, officePhone, ipphone, title, givenName, surname, mail, @{Name='Manager';Expression={(Get-ADUser $_.Manager).sAMAaccountName}}, sAMAccountName | Export-CSV "EU_AD_Properties.csv"
+ CategoryInfo : NotSpecified: (:) [Get-ADUser], ADException
+ FullyQualifiedErrorId : The server has returned the following error: invalid enumeration context.,Microsoft.ActiveDirectory.Management.Commands.GetADUser

It returns details about the user but does not include anything for the manager attribute.
Any ideas?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close