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

Welcome Forums General PowerShell Q&A [Solved]Can't import-csv for Active Directory users

This topic contains 3 replies, has 2 voices, and was last updated by

 
Participant
7 months, 3 weeks ago.

  • Author
    Posts
  • #96885

    Participant
    Points: 0
    Rank: Member

    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 🙂

  • #96893

    Participant
    Points: 134
    Helping Hand
    Rank: Participant
    $users = import-csv "C:\Users\levl\OneDrive\Users Making script\Users-list.csv"
    ForEach ($user in $users) {
        $firstname = $user.'First Name'
    }
    • #96902

      Participant
      Points: 0
      Rank: Member

      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...

  • #96909

    Participant
    Points: 134
    Helping Hand
    Rank: Participant

    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. 😉 Everything else would be a kind of magic ... and strange (at least for me) 😀

The topic ‘[Solved]Can't import-csv for Active Directory users’ is closed to new replies.