AD Bulk change of EmployeeID with Email form CSV Import

I Perez 26 Reputation points

Hi There,

I want to be able to Add/update employeeID attribute in AD from a CSV import, the CSV will have two columns: Email address and EmployeeID, so I want the script to be able to search for the user using email address and then add the corresponding Employee ID. I have no scripting skills and only have the below as a starting point, is someone able to help and see where i've gone wrong.

Import-CSV C:\EIDUpdateTEST1.csv | ForEach-Object {
EmployeeID $($user.EmployeeID)
Get-ADUser -Filter "EmailAddress -eq '$($user.EmailAddress)'" | Set-ADUser -EmployeeID $($user.EmployeeID)

Thank you in advance.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,362 questions
{count} votes

Accepted answer
  1. Rich Matheisen 44,776 Reputation points

    There are two problems I see with your script.

    1. The variable "$user" doesn't exist.
    2. The 2nd line of the script has no double-quotes surrounding the data

    If you simply add the necessary quotation marks you'll still have a problem because the string will be placed into the "success stream" (i.e. the "pipe"). You don't want that to happen (at least not in this case).

    Also, the use of "$($.EmployeeID)" instead of the simpler "$.EmployeeID" isn't necessary as the expression isn't surrounded by double-quotes. [Ignore the missing 'underbar' following the "$" in this paragraph. It's an artifact of the editor when posting code as text!]

    Try this:

    Import-CSV C:\EIDUpdateTEST1.csv | 
        ForEach-Object {
            Write-Host "EmployeeID $($_.EmployeeID)"
            Get-ADUser -Filter "EmailAddress -eq '$($_.EmailAddress)'" | 
                Set-ADUser -EmployeeID $_.EmployeeID
    4 people found this answer helpful.

6 additional answers

Sort by: Most helpful
  1. Robert Walker 0 Reputation points


    Would you know why I'm getting message below please when I run this script?

    PS C:\Windows\system32> Import-CSV C:\ID.csv | 
        ForEach-Object {
            Write-Host "EmployeeID $($_.EmployeeID)"
            Get-ADUser -Filter "EmailAddress -eq '$($_.EmailAddress)'" | 
                Set-ADUser -EmployeeID $_.EmployeeID
    Get-ADUser : The search filter cannot be recognized
    At line:4 char:9
    +         Get-ADUser -Filter "EmailAddress -eq '$($_.EmailAddress)'" |
    +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Get-ADUser], ADException
        + FullyQualifiedErrorId : ActiveDirectoryServer:8254,Microsoft.ActiveDirectory.Management.Commands.GetADUser
    Thanks in advance.

  2. Robert Walker 0 Reputation points

    Thanks for your reply, Rich

    As I don't have excel install on server, CSV is created in note and in format below

    EmailAddress EmployeeID 2710

    I'm not to sure were to add or how to add delimiter in the CSV, Sorry

  3. Robert Walker 0 Reputation points

    Thanks so much for your help Rich.

    I will try this and let you know how I get on, Thanks again.

    When you say Import-CSV cmdlets "-Delimeter" parameter., do I need to change anything below please?

    Import-CSV C:\ID.csv | 
        ForEach-Object {



  4. Robert Walker 0 Reputation points

    Ok, Thanks.

    I will try script tomorrow, and let you know how I get on, Thanks again.



    0 comments No comments