[Solved]Can't import-csv for Active Directory users

Hi guys,

I have a very simple script for importing users from a CSV file

here is the code:

#please enter the path of the file with the users - if you made an Excel file, please convert it to CSV

# by going to the file and do a "save as" and then pick "csv"

#the "$filepath" is the place where you change the path of the csv file

#get the file path:

$filepath = import-csv "C:\Users\levl\OneDrive\Users Making script\Users-list.csv"

#importing the file to the variable and gather the information
$users= $filepath

#Loop through each row and gather information

ForEach ($user in $users) {

    #Get the users info
    $firstname = $user

The script is not completed because i couldn’t make intellisense to complete the script,

after importing the csv file, when i try to write the “$user.” it’s not showing me the headers from the CSV file

here are the headers in the csv file:

First Name,Last Name,SamAccountName,Job Title,Department,Description,Path,ScriptPath

PS: when i run $users i get the list of the users

ok, i’ve figure this out:

So in my case from some strange reason i had to run all the script even though it wasn’t completed, so that PowerShell will import the right properties, only after that i’ve started to see the right Properties according the csv file

so if you encounter with this strange issue when you don’t see the right properties when you try to get all the info from the CSV file, try to write the first few lines in the ForEach loop and then it will start to show you the right properties.

that’s why i like my profession, each day i learn something new :slight_smile:

$users = import-csv "C:\Users\levl\OneDrive\Users Making script\Users-list.csv"
ForEach ($user in $users) {
    $firstname = $user.'First Name'

yes i did that,
look at my update :\

this is very strange, only after i started to write few of the properties by hand and ren the script it actually started to loop through the $user and started to show me the right properties.

very awkward…

Ah … ok … now I know what you meant. Yes, intellisense has to know about the objects you like to work with. But if you didn’t run the code you create the objects with the intellisense cannot know the objects. That’s not strange - that’s feature by design. :wink: Everything else would be a kind of magic … and strange (at least for me) :smiley: