How to change format of phone numbers in PowerShell?


we need append area code , hyphen in front of office phone number field in domain user account our users have office phones changing 7 digit numbers 10 digit numbers.

i found script finds , edits phone numbers, author chose different way format numbers.

this part of script need change:

# format number xxx xx xx xxx.
        $phone = '{0} {1} {2} {3}' -f$phone.substring(0,3),$phone.substring(3,2),$phone.substring(5,2),$phone.substring(7,3)

i'm trying figure out how edit formats xxx-xxx-xxxx (3 digit area code, hyphen, 3 digit prefix, hyphen, 4 digit number) instead of xxx xx xx xxx.

can show how rewrite section?


the modified script:

# format number xxx-xxx-xxxx.          $phone = '{0}-{1}-{2}' -f $phone.substring(0,3),$phone.substring(3,3),$phone.substring(6,4)

hope helps.

regards,

thennet


please take moment "vote helpful" and/or "mark answer", applicable. helps community, keeps forums tidy, , recognises useful contributions. thank you!



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Group Policy Event ID 1058 Error Code 1326 (The user name or password is incorrect)

Suspicious event log Event ID: 4905

DCOM received error "2147746132" from...