question

IPerez-6289 avatar image
0 Votes"
IPerez-6289 asked RichMatheisen-8856 commented

AD Bulk change of EmployeeID with Email form CSV Import

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.
Perez

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered RichMatheisen-8856 commented

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




· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

HI Rich,

Many thanks for fixing the script, aside a missing closing bracket your script worked a charm.

Thanks again.

Perez

0 Votes 0 ·

An embarrassing failure of copy-and-paste! :-o

0 Votes 0 ·