Add Ad users Info

Welcome Forums General PowerShell Q&A Add Ad users Info

This topic contains 6 replies, has 4 voices, and was last updated by

 
Inactive
2 years, 4 months ago.

  • Author
    Posts
  • #46674

    Inactive
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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

  • #46706

    Inactive
    Points: 0
    Rank: Member

    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

    Participant
    Points: 20
    Rank: Member

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

  • #46712

    Inactive
    Points: 0
    Rank: Member

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

  • #46827

    Participant
    Points: 0
    Rank: Member

    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

      Inactive
      Points: 0
      Rank: Member

      Many Thanks Curtis, Alex and Mark.

The topic ‘Add Ad users Info’ is closed to new replies.