Add Ad users Info

Tagged: 

This topic contains 6 replies, has 4 voices, and was last updated by Profile photo of  Anonymous 4 months, 2 weeks ago.

  • Author
    Posts
  • #46674
    Profile photo of
    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
    Profile photo of Alex
    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 4 months, 3 weeks ago by Profile photo of Alex Alex.
  • #46706
    Profile photo of
    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
    Profile photo of Mark Prior
    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
    Profile photo of
    Anonymous

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

  • #46827
    Profile photo of Curtis Smith
    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
      Profile photo of
      Anonymous

      Many Thanks Curtis, Alex and Mark.

You must be logged in to reply to this topic.