function Format-ADPerson-as-e164 ($LDAPpath) { $changed=$false $Contact=[ADSI]($LDAPPath) if($contact.psbase.properties.facsimileTelephoneNumber) {$temp = Format-Number-as-E164($contact.facsimileTelephoneNumber) if ($temp -ne $contact.facsimileTelephoneNumber) {$contact.facsimileTelephoneNumber=$temp $changed=$TRUE} } if($contact.psbase.properties.homePhone) {$temp = Format-Number-as-E164($contact.homePhone) if ($temp -ne $contact.homePhone) {$contact.homePhone=$temp $changed=$TRUE} } if($contact.psbase.properties.ipPhone) {$temp = Format-Number-as-E164($contact.ipPhone) if ($temp -ne $contact.ipPhone) {$contact.ipPhone=$temp $changed=$TRUE} } if($contact.psbase.properties.mobile) {$temp = Format-Number-as-E164($contact.mobile) if ($temp -ne $contact.mobile) {$contact.mobile=$temp $changed=$TRUE} } if($contact.psbase.properties.pager) {$temp = Format-Number-as-E164($contact.pager) if ($temp -ne $contact.pager) {$contact.pager=$temp $changed=$TRUE} } if($contact.psbase.properties.PrimaryInternationalISDNNumber) {$temp = Format-Number-as-E164($contact.PrimaryInternationalISDNNumber) if ($temp -ne $contact.PrimaryInternationalISDNNumber) {$contact.PrimaryInternationalISDNNumber=$temp $changed=$TRUE} } if($contact.psbase.properties.TelephoneAssistant) {$temp = Format-Number-as-E164($contact.TelephoneAssistant) if ($temp -ne $contact.TelephoneAssistant) {$contact.TelephoneAssistant=$temp $changed=$TRUE} } if($contact.psbase.properties.TelephoneNumber) {$temp = Format-Number-as-E164($contact.TelephoneNumber) if ($temp -ne $contact.TelephoneNumber) {$contact.TelephoneNumber=$temp $changed=$TRUE} } if ($changed) { write-host $contact.name changed $contact.setInfo() } } function Format-Number-as-E164 ([string]$Number) { if ($number.length -gt 5) { if ($number.substring(0,2) -ne '08') { if ($number.substring(0,2) -eq '00') {$number='+' + $number.substring(2) } if ($number.substring(0,1) -eq '0') {$number='+44 '+ $number.substring(1) } $number = $number.replace("+440", "+44") $number = $number.replace("+44 0", "+44") $number = $number.replace("+44(0)", "+44") $number = $number.replace("+44 (0)", "+44") $number = $number.replace("+44(0", "+44(") $number = $number.replace("+44 (0", "+44 (") } } $number }