Getting managers names

Hello all! I am very new to powershell scripting. I have some experience with cmdlets but get a bit fuzzy when throwing them together in a script. Especially when importing/exporting a csv file.

So here is what I have and need... any help would be extremely helpful:

I have a csv file named "Users" with a header of "ID". In the ID column, I have the login IDs of over 500 users and I need to get the login IDs of their managers and export both (the original users ID in a column named "User" and their managers' login IDs in a column named "Mgr").

Again, any help would be extremely appreciative

May 19th, 2015 11:55am

Hi,

Use Import-Csv to read in your input file, ForEach-Object to loop, Get-ADUser to get user details back, and finally Export-Csv to output your results. Here's syntax links:

http://ss64.com/ps/import-csv.html

http://ss64.com/ps/foreach-object.html

http://ss64.com/ps/get-aduser.html

http://ss64.com/ps/export-csv.html

Free Windows Admin Tool Kit Click here and download it now
May 19th, 2015 12:00pm

Import-Csv C:\Users.csv | Foreach {
  Get-ADUser $_.User -Properties Manager | Select samAccountName, @{N='Manager';E={(Get-ADUser $_.Manager).SamAccountName}}
} | Export-Csv C:\UserInfo.csv -NoTypeInformation		
May 19th, 2015 12:18pm

Every user throws this type of error and the export is empyt.

Get-ADUser : Cannot bind parameter 'Identity'. Cannot convert value "@{User={userID}}" to type
"Microsoft.ActiveDirectory.Management.ADUser". Error: "Cannot convert the "@{User={userID}}" value of type "System.Management.Automation.PSCustomObject" to type "Microsoft.ActiveDirectory.Management.ADUser"."
Free Windows Admin Tool Kit Click here and download it now
May 19th, 2015 12:37pm

Get-ADUser $_ -

Should be

Get-ADUser $_.User

CSV file must look like this:

User
joe
mary
sam
john

May 19th, 2015 12:43pm

Get-ADUser $_ -

Should be

Get-ADUser $_.User

CSV file must look like this:

User
joe
mary
sam
john

Free Windows Admin Tool Kit Click here and download it now
May 19th, 2015 12:50pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics