BarryCrosby
Technical User
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?
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?