Monday, July 11, 2011

Search AD and Add Employee ID–PowerShell Script

Script #1

Here is a simple PowerShell script which you can use to add Employee ID in a user object. This script requires PowerShell Active Directory module.

Note: I am not searching AD for the user account.  My assumption is the user account already exist in AD. 


Input file – Input file (Users.csv) contains user names and employeeID in the following format:


You can download this script from the following locations: -

Microsoft TechNet Gallery -

Script #2 -  Search AD using email address and update the employee ID value.


Input file (users.csv) contains email address and employee ID in the following format:


Download -

Microsoft TechNet Gallery -


More scripts -


How can this be modified to allow multiple attributes to be changed. e.g. telephoneNumber to be changed along with employeeNumber

Update the input file with telephone number in the following format:


And update the code with the correct attribute -

Fax facsimileTelephoneNumber
Home homePhone
Notes info
IP phone ipPhone
Mobile mobile

Here is the updated script:

Import-module ActiveDirectory
Import-CSV "C:\Scripts\Users.csv" | % {
$User = $_.UserName
$ID = $_.EmployeeID
TelN = $_. TelNumber
Set-ADUser $User -employeeID $ID – homePhone TelN

Thanks Santosh ! unfortunately I still have trouble

problem appears to be with the attribute "telephoneNumber" and "ipPhone". When I change the script to modify these attributes with "hometelephone" and "mobile" they work just fine.

Script is

Import-module ActiveDirectory
Import-CSV "C:\Scripts\test.csv" | % {
$User = $_.UserName
$ID = $_.empNumber
$TelN = $_.telNumber
$IP = $_.ipP
#Set-ADUser $User -employeeNumber $ID -telephoneNumber $TelN -ipPhone $IP

CSV file is


Error is

Set-ADUser : A parameter cannot be found that matches parameter name 'ipPhone'.
At C:\scripts\modify2.ps1:7 char:46
+ Set-ADUser $User -employeeNumber $ID -ipPhone <<<< $IP
+ CategoryInfo : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADUser

Any suggestions ??

The Set-ADUser cmldet doesn’t have an alias for the AD ipPhone attribute. You can see all available alias in the link.

However, you can LDAP reference and –instance parameter to set these values.

Here is an example:

$UserN = Get-ADUser Testuser1 -Properties ipPhone
$UserN.ipPhone = "111.222.333.444"
Set-ADUser -instance $UserN

Santhosh, thank you for this article. I am new to PowerShell and have this question:

We already have EmployeeID attribute populated but it does not show up in the property page of a user in ADUC. How can I get that attribute to appear in ADUC?

Thanks so much for your help.

By default, it won’t show up in ADUC. You need to customize the display. Mike has a blog on this procedure -

Thank you. I was hoping to add it as a display on a tab in ADUC, as we have 100s of people using ADUC. Don't want to call up a script everytime they use it.

Thanks though!!!

This is a onetime change but if you thinking about a Tab or item in the Tab, you need to modify the GUI (Display Specifiers)…not that easy ;) Here are some info..

hello, I need to edit multiple attributes at the same time:
employeeid, EmployeeType, employeenumber, codepage

Hi can one help me to update Employee id and Department id for AD users

Set-ExecutionPolicy RemoteSigned
Import-module ActiveDirectory
Import-CSV "c:\users.csv" | % {
$User = $_.UserName
$ID = $_.EmployeeID
$userobj.EmployeeID = $ID


You can update any value using this method/script. Just use the correct attribute name. Here is a reference link -


Same answer!

You can update any value using this method/script. Just use the correct attribute name. Here is a reference link -

hi, I'm new to poweshell commands. I try to update my employee numbers for more than 1000 employees. I created file as below :-
Import-module ActiveDirectory
Import-CSV "c:\temp\users.csv" | % {
$User = $_.UserName
$ID = $_.empNumber
Set-ADUser $User -employeeID
Saved this file as .ps1, when I tried to run it I will get below error :-
Set-ADUser : Cannot validate argument on parameter 'Identity'. The argument is
null. Supply a non-null argument and try the command again.
At C:\TEMP\UpdateEmployeeID.ps1:5 char:11
+ Set-ADUser <<<< $User -employeeID
+ CategoryInfo : InvalidData: (:) [Set-ADUser], ParameterBindingV
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Activ

how can I rectify this error. if we want to follow other steps then please update me on

Hi Siva,
Your blog has been really helpful, keep up the great work

Hi Siva,
How can I use your script to edit the Office field in an AD Contact rather than an AD User?

Never mind. I just changed the Set-ADUser command to Set-Contact and ran the script from our Exchange Server so that it used the Exchange Server commands. Worked Great!!

Hello, I know this is an old post. but I am getting an error message (Set-ADUser : Cannot find an object with identity "username" under: 'dc=domain.dc=com. also, confirmed that the user account does exist.
any ideas?

Dear Santosh,

thanks for your valuable support for so many system administrators,i have always been a fan of you,have read lots of troubleshooting tips and articles written by you,

I want to add assistant field for bulk users ,so in this case how will be script modified,i have all the user account with assistant details.

You can. Use the correct attribute. I have listed all the attribute detail here -

Do you have this user? did you verify this?

This comment has been removed by the author.

I too am getting this error message. I ran this on a single user and wondered if it has to do with the fact that the user is in different container?

I too am getting this error message. I ran this on a single user and wondered if it has to do with the fact that the user is in different container?

I need to update employee number for morethan 200 employees with the help of their email ids. Requesting you to please provide the script and csv file format

Post a Comment

Popular Posts


Twitter Delicious Facebook Digg Stumbleupon Favorites More