Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Import Phone Number list from CSV with Powershell. Based on EmployeeID

This seems so simple, but I have spent hours digging and could not find a solution. I try to manipulate others scripts to meet my needs but I keep jacking it up somehow. I am not great with Powershell.

I have the following command that seems to work great. It successfully pulls the name/MobilePhone and imports it into AD.

Import-Csv -Path .\test123.csv | ForEach {Set-ADUser $_.name -mobilePhone $_.MobilePhone}

The problem is that the default "ADUser" value in AD is very inconsistent. Over the years people have created ADUser accounts in many different ways. Some using the employees ID, some being FirstnameLastInitial, some being fullname. So I am wanting to mass update the mobilePhone value with users EmployeeID value instead. As everyone should have an accurate EmployeeID value…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Does anyone know the command I can use to meet this requirement?

The test123.csv has two columns. One "name" column and one "MobilePhone" column.

>Solution :

Looking up a user by employeeId can be done, but be aware that the documentation shows that it is not indexed. So to find a user by employeeId, it has to look at every user account until it’s found. That can make for a slow query, depending on how many users you have on your domain.

But here’s how you would do it, and you can decide if it’s too slow, or if your AD admins will yell at you for making a bunch of these queries.

Use Get-ADUser to find the user, then pipe that into Set-ADUser:

Import-Csv -Path .\test123.csv | ForEach {
    Get-ADUser -LDAPFilter "(employeeId=$($_.name))" | Set-ADUser -MobilePhone $_.MobilePhone
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading