Reputation: 11
I'm trying to import and replace telephone numbers in AD via a Powershell script from an exported and updated CSV file.
The script I'm using is:
Import-Csv C:\test2.csv | ForEach-Object {
Set-ADUser -Identity $_.samAccountName -Replace @{
telephoneNumber=$_.OfficePhone;HomePhone=$_.HomePhone;MobilePhone=$_.MobilePhone}
}
The formatting of the CSV is:
samaccountname,OfficePhone,HomePhone,MobilePhone
Username,Phone no, phone no, phone no
When trying to import it I get the error:
C:\Users\account\Desktop\ps2.ps1:2 char:13
+ Set-ADUser <<<< -Identity $_.samAccountName -Replace @{telephoneNumber=$_.OfficePhone;HomePhone=$_.HomePhone;Mobil
ePhone=$_.MobilePhone}
+ CategoryInfo : InvalidOperation: (1305:ADUser) [Set-ADUser], ADInvalidOperationException
+ FullyQualifiedErrorId : replace,Microsoft.ActiveDirectory.Management.Commands.SetADUser
Does anyone have any idea?
Upvotes: 1
Views: 21925
Reputation: 11
It works fine.
Import-Csv E:\test.csv | ForEach-Object {Set-ADUser -Identity $_.samAccountName -Replace @{Mobile=$_.MobilePhone}}
Upvotes: 1
Reputation: 36322
Only thing I see is that the -Replace operator requires that you use LDAP display fields and MobilePhone does not exist. Use Mobile instead.
Check out this site for a great table listing all the LDAP user attributes. Or you can use the MSDN page which is considerably less useful because it doesn't show LDAP display names unless you click on links for each field.
Upvotes: 1