Reputation: 25
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...
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.
Upvotes: 2
Views: 1595
Reputation: 40958
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
}
Upvotes: 1