Add Ad users Info

Tagged: 

This topic contains 6 replies, has 4 voices, and was last updated by  Anonymous 1 year, 2 months ago.

  • Author
    Posts
  • #46674

    Anonymous

    hi all,
    i want to ask how can i use hash table to insert different attributes to user accounts like if a user has this@test.com email then insert description, employID, Office and some more attributes from a csv file.

    my CSV file contains
    Email Address, description, employID, Manager,JobTitle

    thanks

  • #46681

    Alex
    Participant

    Hi Ali,

    What you can do is:

    $CSV = Import-csv path to your CSV file
    
    #As long as you have a primary key in your CSV (common identifier)
    
    Foreach($items in $csv){
    get-aduser $items.email | set-aduser -description $items.description -employeeID $items.employID -Manager $items.manager -jobtitle $items.jobtitle
    }
    
    

    This should update the the users from the CSV

    • This reply was modified 1 year, 2 months ago by  Alex.
  • #46706

    Anonymous

    Hi Alex,
    thanks so much. i also get a solution from google but i am not able to understand LDAP Filter attribute highlighted in Bold Letters, can you make me understand

    Get-ADUser -LDAPFilter ('(SamAccountName={0})' -f $user.SamAccountName)

  • #46709

    Mark Prior
    Participant

    I believe LDAP filters only load that one attribute instead of loading all properties per user in your case, making the search faster

  • #46712

    Anonymous

    It Means SamAccountName={0} means just load the SamAccountName Property.

  • #46827

    Curtis Smith
    Participant

    Get-ADUser -LDAPFilter ('(SamAccountName={0})' -f $user.SamAccountName)

    If it using the format operator to substitue {0} for the value of $user.SamAccountName

    For example

    $user = [pscustomobject]@{SamAccountName = "User1"}
    
    '(SamAccountName={0})' -f $user.SamAccountName
    

    Results:

    (SamAccountName=User1)

    so

    Get-ADUser -LDAPFilter ('(SamAccountName={0})' -f $user.SamAccountName)

    becomes

    Get-ADUser -LDAPFilter (SamAccountName=User1)
    • #47166

      Anonymous

      Many Thanks Curtis, Alex and Mark.

You must be logged in to reply to this topic.