none
Updating AD users using a field from a CSV RRS feed

  • Question

  • Hi,

    I was wondering is somebody could assist with a very simple process I am trying to complete but I just do not understand how.

    I have the following piece of PowerShell below to query users in AD by their EmployeeID and works as expected.

    Import-csv C:\Temp\raw.csv | ForEach-Object {
        $ID = $_.employeeID
        get-aduser -filter {employeeid -eq $ID} -Properties * | select-object emailaddress,employeeNumber,employeeID,surname,givenname | Export-Csv C:\Temp\exportADUser.csv -Append -NoTypeInformation

    }

    The headers in my CSV are as follows:

    UserEmail,EmployeeNumber,EmployeeID,LName,FName

    From the query above I would then like to update the EmployeeNumber for each AD user using the the value in the CSV.

    I assume this will require the Set-ADUser cmdlet and the Foreach loop but I'm unsure how to amend my current PowerShell to get this working.

    If anyone could assist that would be great.

    Kind Regards

    Dean

    Monday, February 18, 2019 8:49 AM

Answers

All replies

  • Please format your code as code using the code posting tool provided on the edit bar of the post editor. Thanks.

    This should work:

    Import-Csv -Path 'C:\Temp\raw.csv' | 
        ForEach-Object {
            get-aduser -filter "employeeid -eq '$($_.employeeID)'" -Properties employeeNumber, employeeID | 
                Set-ADUser -EmployeeNumber $_.employeeNumber
        }


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Monday, February 18, 2019 9:01 AM
  • Many Thanks for the assistance
    • Marked as answer by exchinfo Tuesday, February 19, 2019 5:21 PM
    Monday, February 18, 2019 11:04 AM