Active Directory Import CSV Powershell Multiple Users RRS feed

  • Question

  • I for the life of me can not figure out a way to do this. I am trying to change properties on multiple users. I want the script to match the active directory description to the description column of the CSV file and then change the properties matched to that description. We have unique identifiers in the description. So connect the csv object to AD object and then change the properties of that object. Thank you for any help!

    • Moved by Bill_Stewart Wednesday, December 12, 2018 9:41 PM Abandoned
    Monday, September 10, 2018 3:19 AM

All replies

  • We cannot help you if you do not post your script.


    Monday, September 10, 2018 3:29 AM
  • Oops Sorry!

    !users = import-csv "C:\Users.csv"

    !users|Get-ADUser -Filter * -Properties Description -SearchBase "OU=OUtest,DC=test,DC=local"|foreach{Set-ADUser -Identity "Description -eq $users.description" -Department $users.Department -Title $users.Position}

    Monday, September 10, 2018 3:39 AM
  • A correct format for your script would be easier to understand.  Also your scrip makes no sense from any perspective.

    To change a user use "Set-AdUser".  Start by reading the help for the CmdLets.

    What is "!user".  There is no such command or variable.

    You need to learn the basics of PowerShell before trying to do anything else: Learn PowerShell  

    Once you have some basic understanding of PowerShell then try to ask your question.


    Monday, September 10, 2018 3:50 AM
  • Meant $users instead of !users. And okay. Such great help... lol if I needed help with basics of powershell. I would of asked that. But I asked for help to script a command to get a user from AD, then match it to the user in the CSV, and then change their attributes in Active Directory from the CSV. If I knew powershell, apparently to the level of you, I wouldn’t be asking for help.
    If there is an easier way then feel free to guide me down that road. I just need to change properties of thousands of users. The way they’re getting it done is one by one and I felt that is silly, trying to make it easier.
    • Edited by CWhite7 Monday, September 10, 2018 4:36 AM
    Monday, September 10, 2018 4:25 AM
  • You have not said what is in your CSV.  You need to know what D considers a "user".  You code seems to assume that all users are needed to match a user.

    If you had learned a basic PowerShell and knew a little about AD then you might see why you code is pointless.

    To get a user the "Get-AdUser" must use an identifier and not "*".  TO do that you need to know what kind of identifier is in the CSV.

    Get-AdUser -Filter "someADattribute -eq 'user identifier'"

    belp Get-AdUser -online


    Monday, September 10, 2018 4:48 AM
  • $users = Import-Csv "C:\Employee Info Update2.csv"
    foreach ($user in $users){
    $employee = $user.employeeid
    $Title = $user.Position
    Get-ADUser -Filter {Description -like '*$employee*'} -SearchBase "OU=OUtest,DC=test,DC=local"|
    Set-ADUser -Title $Title

    Any better? I am trying to get it to pull users that have more than just their employee id in their description, but cant seem to get that to work. Works if their description is equal to the employeeid on the CSV, but some descriptions have like '4324 - Clerk'

    • Edited by CWhite7 Monday, September 10, 2018 1:47 PM
    Monday, September 10, 2018 1:16 PM
  • Please read the help for the CmdLet to learn what an "Identity" is.

    help set-aduser -online

    What is "EmployeeID"?

    TO find a user with the "EmployeeID" attribute:

    Get-AdUser -Filter "EmployeeID -eq '$employeeID'"



    Monday, September 10, 2018 6:17 PM
  • I know what an identity is. Active directory has been setup with the employeeid in the description of the users. that is why I have to do it that way.
    Monday, September 10, 2018 6:30 PM
  • Get-AdUser -Filter "Description -eq '$employeeID'"

    This is a very unreliable way to manage users and AD.


    Monday, September 10, 2018 6:37 PM
  • You don't say... not my decision lol
    Monday, September 10, 2018 8:02 PM