We help IT Professionals succeed at work.

Importing a CSV with First + Last Name and performing action

I'm trying to figure out how to, in PowerShell/Exchange PowerShell/Quest Powershell how to import a CSV that contains one column header is "user" and in the column is a list of employee First name and Last name, for example:
User
John Smith

Open in new window


I do:
$people = Import-Csv .\escalationlist.csv | %{$_.User}

Open in new window

then
get-qaduser $people

Open in new window


But I get:

Get-QADUser : Cannot convert 'System.Object[]' to the type 'Quest.ActiveRoles.ArsPowerShellSnapIn.Data.IdentityParamete
r' required by parameter 'Identity'. Specified method is not supported.
At line:1 char:12
+ Get-QADUser <<<<  $people
    + CategoryInfo          : InvalidArgument: (:) [Get-QADUser], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.GetUserCm
   dlet


If I could put quotes around $people then one would think it would work


Is there a way to lookup the AD username/account name based off this display name?
Comment
Watch Question

Professional Services Engineer
BRONZE EXPERT
Commented:
It looks like you're trying to get an Array full of people.

Try this:

$People | Get-QADUser

That should say something like:

For every person in $People, give me their information.  This will be very long output, but this is the way you're going to get past this error.

HTH,

Dale Harris
Bradley FoxLAN/WAN Systems Administrator
BRONZE EXPERT

Commented:
Try this:


get-qaduser -Identity $people

get-qaduser -Identity '"$people"'

Open in new window

Author

Commented:
Ah ok yes DaleHarris that works.

Do you know if the % sign in "$people = Import-Csv .\escalationlist.csv | %{$_.User}" means? Is that even necessary?
Dale HarrisProfessional Services Engineer
BRONZE EXPERT
Commented:
It's necessary because you're saying "Get all the .User variables from the csv on the left".

The % sign is the same as Foreach-Object

It's a little out of order because you're saying C = A | B

Does that help?

The Pipe command can be a little confusing at first.  The best analogy I can come up with is this:

You have a race full of people.  If you want to filter out people, you can use the ? or Where-Object.  So you can say something like this:

A Huge Race | If they are Men | If they are Under 60 | If they weigh over 100 lbs

So as you go from left to right, you're slowly cutting out more people and by the end, you have only males that are under 60 and over 100 lbs.  If you want to store that to a variable, you begin with a variable like $FilteredRacePeople.  So it looks like this:

$FilteredRacePeople = $RaceGroup | ?{$_.gender -eq "Male"} | ?{$_.age -lt 60} | ?{$_.weight -gt 100}

Hope that helps.

Dale Harris

Author

Commented:
That's awesome

But I'm trying to get the distinguished name from the display name. Trying this doesn't seem to work:

foreach ($user in $people) {$userDN =  get-qaduser $user | %{$_.distinguishedName}}

Open in new window

Dale HarrisProfessional Services Engineer
BRONZE EXPERT
Commented:
I thought it was "$_.dn" not Distinguished Name.

If you want to see what a variable has, try this:

$Person = Get-QADUser "john.smith"
$Person | gm

gm = Get-Member

This will show you each and every method/property you can touch/see.

DH
Dale HarrisProfessional Services Engineer
BRONZE EXPERT
Commented:
What you're going to find with your code is you're going to be replacing $UserDN every single time.  You're going to want an array I'm assuming with many values.

Try this:

$UsersDN = $People | Get-QADUser | %{$_.dn}

Now you can do a $UsersDN.length and see how many people in your list.

DH

Author

Commented:
Ah ok cool and I think my previous command was wrong, this seemed to work:

$people | Get-QADuser | %{$_.Directoryentry.distinguishedname}

And then that works with your solution, thanks again for your help

Explore More ContentExplore courses, solutions, and other research materials related to this topic.