Link to home
Start Free TrialLog in
Avatar of Mücahit Koç
Mücahit Koç

asked on

Active Directory - User Telephone Number copy to ipPhone Atttribute

I am trying to copy the last 4 characters of the phone number with the following scenario, but I get an error. Help please :(

Error :

You cannot call a method on a null-valued expression.
At line:3 char:5
+     $phoneNumber = $_.OfficePhone.Substring($_.OfficePhone.Length - 4,4)



Get-ADUser -Filter * -SearchBase 'OU=Test 1,DC=domain,DC=com' -Properties OfficePhone | ForEach {

    $phoneNumber = $_.OfficePhone.Substring($_.OfficePhone.Length - 4, 4)

    Set-ADUser -Identity $_.SamAccountName -Replace @{ipPhone=$phoneNumber}

}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mücahit Koç
Mücahit Koç

ASKER

Thank you very much for the information, we have solved the problem with your support