Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Powershell return samaccountname for manager in csv output

Status
Not open for further replies.

BarryCrosby

Technical User
May 27, 2003
20
AU
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?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top