What am I missing with this?

Simple:

Trying to pull from a csv file with User.Names (AD) using the import-csv. with one column and no headers ( although I could add them )

Then I’m trying this:

Get-ADUser -Properties manager,displayname | select displayName,@{name='userID';expression={$_.name}},@{name='Division';expression={$_.department}},@{name='Manager';expression={ ([ADSI]"LDAP://$($_.manager)").displayname }}
$userData | Export-Csv -Path C:\Users\knouset\Documents\Scripts\managerlist.csv -NoTypeInformation

No I am aware the Get-ADuser is not defined above. If I use the “get-adser User.Name” I get the intended output.

 

So what I would like to do is combine these and have the users pulled from the names.csv then output to the manager list.

 

Im fairly novice to power shell and trying to expand my knowledge, I did a search but didnt find anything specially for this. If its there I apologixwe in advance and please link it to me if I missed it.

 

Thanks

Topher

 

AS a side note:

 

I did try the following:

$UserData = Import-CSV -Path C:\Users\Folder\Documents\Scripts\names.csv 
foreach ($Users in $UserData)
{
Get-ADUser -Properties manager,displayname | select displayName,@{name='userID';expression={$_.name}},@{name='Manager';expression={ ([ADSI]"LDAP://$($_.manager)").displayname }}
}
$userData | Export-Csv -Path C:\Users\Folder\Documents\Scripts\managerlist.csv -NoTypeInformation

Although, I am still missing something.

 

 

Hi toknouse43,

In your scripts, specifically, @{name=‘userID’;expression={$_.name}} that return the display name of the user. If you need the username of the user, you should use the SamAccountName property. Also, using the Import-Csv returns an object which requires headers to import the data.

pwshliquori

pwshliquori

 

Thank you. I’m about to go work on these

get-content names.txt | get-aduser

@tknouse43

try below code it will work for you …
Get-ADUser we have a mandiory field that is “Filter” parameter which needs to pass or put * that was missing your code.

Code:
Get-ADUser -Filter * -Properties manager,DisplayName,name | select DisplayName,@{name=‘UserID’;expression={$.name}},@{name=‘Manager’;expression={ ([ADSI]"LDAP://$($.manager)").displayname }} | export-csv -Path C:\Users\Folder\Documents\Scripts\managerlist.csv -NoTypeInformation

Chrees !!!
Nitesh