How to change format of phone numbers in PowerShell?

We need to append the area code and hyphen in front of the office phone number field in their domain user account for all our users that have office phones now that we are changing from 7 digit numbers to 10 digit numbers.
I found a script that finds and edits phone numbers, but the author chose a different way to format the numbers.
This is the part of the script I need to change:
# Format number as 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 to figure out how to edit that so that it formats it as xxx-xxx-xxxx
(3 digit area code, hyphen, 3 digit prefix, hyphen, four digit number) instead of xxx xx xx xxx.
Can someone show how to rewrite this section?

The modified script:
# This format number as xxx-xxx-xxxx.
$Phone = '{0}-{1}-{2}' -f $Phone.Substring(0,3),$Phone.Substring(3,3),$Phone.Substring(6,4)
Hope this helps.
Regards,
thennet
Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable. This helps the community, keeps the forums tidy, and recognises useful contributions. Thank you!

Similar Messages

  • How can I get the phone numbers in contacts to appear with dashes between the first 3 numbers, the next 3 numbers, and the last 4 numbers?  Until very recently it did so.  Contacts on my macbook pro does show up this way.  I do have a mobile me account an

    How can I get the phone numbers in contacts to appear with dashes between the first 3 numbers, the next 3 numbers, and the last 4 numbers?  Until very recently
    it did so.  Contacts on my macbook pro does show up this way.  I do have a mobile me account and in the past syncing was no problem.  What setting has changed?

    The phone number format as well as the date language and format and the time format are controlled by the Region Format setting. Go to Settings > General >International > Region Format.  When you change a region format, you can go back one page (to International) and see an example of the date/time/phone number format that your selected region format will produce.

  • Standardizing the format of phone numbers in contacts

    I am looking for a script or app that will quickly standardize the format of phone numbers in my contacts.  Any suggestions?

    Before you sync your iPhone the next time, activate the option "sync addressbook" and "replace all Contacts on iPhone". The next sync will replace your contact info on your phone. From that point on all contact infos will be the same on your mac and and your phone. And changes or new infos will also be seen on both systems.
    Hope this helps

  • How do i get my phone numbers back after i restored phone back to new?

    how do i get my phone numbers back after i restored phone back to new?

    Where were you syncing the contacts to, iCloud, the computer and Outlook, an email account? That is where you get them back from.

  • I have file with 500 pages created from AutoCad file. In all pages, I have different document numbers.The file is not editable in pdf. How to change all the document numbers using "Comment" feature? Any alternate method?  alternate method? I have Adobe Ac

    I have pdf file with 500 pages created from AutoCad file. In all pages, I have different document numbers.The file is not editable in pdf. How to change all the document numbers using "Comment" feature? Any alternate method?  alternate method? I have Adobe Acrobat X Pro and Windows -7 platform.

    Yes, I just want to cover up all the pages for those particular area of document numbers.
    Nothing sensitive about it. I just want to show the correct document numbers on all pages in print out.
    So, I wanted to cover up by comments, but commenting on each page will be difficult. So, I wanted to comment the same on all pages.

  • How do I get my phone numbers from my IPhone 4 to IPhone 4S

    how do I get my phone numbers from my IPhone 4 to my new IPhone 4S?

    Contacts are designed to be synced with a supported address book app on your computer, or over the air with an email account that supports it. Not a good idea to depend on an iPhone or any cell phone alone for contacts which can be lost or stolen or damaged beyond repair by being dropped, etc.
    If you are syncing contacts with a supported address book app on your computer, you select the same under the Info tab for your iPhone sync preferences with iTunes followed by a sync.
    If you are syncing contacts over the air with an email account that supports it, create the account with the Mail app on your new iPhone and turn Contacts on for over the air syncing with the account settings on the iPhone.
    Contacts are included with the iPhone's backup. If your iPhone is being backed up with iTunes on your computer, the first time you connect a new iPhone to iTunes on a computer being synced with another iPhone, you are prompted to transfer the backup for the other iPhone or set up the new iPhone as a new iPhone.

  • How to change format of text in ticker view?

    Hi all,
    How to change format of text in ticker view?
    Thanks

    Hi,
    If you want to format the entire ticker with particular format then put in the Beginning text
    before Table tag
    put the font tag with needed attributes
    <Font> <table....>
    In the end text after table tag
    <table> close the font tag
    Thanks,
    Vino
    Edited by: Vinodh NK on Mar 18, 2010 4:36 AM
    Edited by: Vinodh NK on Mar 18, 2010 4:36 AM

  • How do I restore all phone numbers deleted more than 1 week ago?

    How do I restore all phone numbers after they were deleted more than a week ago?

    erin --
    If you've emptied your Mail trash, you can't.

  • How to format unformated phone numbers Please...,

    Hello Good Evening, i have a phone number table which has single column in it with different style of phone numbers, i am trying to change it as required format
    Required format are
    1) Always start with a 1
    2) Only Left 14 charcaters after spaces elimination (if there is any)
    3) No spaces
    4) special characters like (,),-,/ need to replace with '.'
    5) if there is no separation/space then format 1.800.###.#### need to apply
    create table #myphoneno (phone varchar(20))
    Insert into #myphoneno values  ('(866) 987-3847' ) --- Rule 1,3,4
    Insert into #myphoneno values  ('1-800-222-SAVE(7283)') --- Rule 2,4
    Insert into #myphoneno values  ('(800) 111-4015') --Rule 3,4
    Insert into #myphoneno values  ('18002288775')  ---Rule 5
    Insert into #myphoneno values  ('(800) 2223415')--- Rule 1,3,4,5
    Insert into #myphoneno values  ('(800) 2-MOHAN')--- Rule 1,,3,4
    Insert into #myphoneno values  ('1-800-228-4995') ---Rule 4
    Insert into #myphoneno values  ('877-233-0112')---- Rule 1,4
    Insert into #myphoneno values  ('800 228 3315')--- 1,3,4
    Insert into #myphoneno values  ('18002284225')---Rule 5
    Insert into #myphoneno values  ('800/219-1140') --- Rule 1,4
    Insert into #myphoneno values  ('1 (855) ECO-8107') -- Rule 3,4
    Insert into #myphoneno values  ('(888) BOM4BQC')-- Rule1,3,4
    Insert into #myphoneno values  ('877-421K-MOX')-- Rule 1,4
    Select * from #myphoneno
    ---- Expected results as below
    create table #myphonenoExpected (phone varchar(20))
    Insert into #myphonenoExpected values  ('1.866.987.3847' )
    Insert into #myphonenoExpected values  ('1.800.222.SAVE')
    Insert into #myphonenoExpected values  ('1.800.111.4015')
    Insert into #myphonenoExpected values  ('1.800.228.8775')
    Insert into #myphonenoExpected values  ('1.800.222.3415')
    Insert into #myphonenoExpected values  ('1.800.2.MOHAN')
    Insert into #myphonenoExpected values  ('1.800.228.4995')
    Insert into #myphonenoExpected values  ('1.877.233.0112')
    Insert into #myphonenoExpected values  ('1.800.228.3315')
    Insert into #myphonenoExpected values  ('1.800.228.4225')
    Insert into #myphonenoExpected values  ('1.800.219.1140')
    Insert into #myphonenoExpected values  ('1.855.ECO.8107')
    Insert into #myphonenoExpected values  ('1.888.BOM.4BQC')
    Insert into #myphonenoExpected values  ('1.877.421K.MOX')
    Select * from #myphonenoExpected
    Thank you in advance
    Asiti

    USE [Northwind]
    create table #myphoneno (phone varchar(20))
    Insert into #myphoneno values ('(866) 987-3847' ) --- Rule 1,3,4
    Insert into #myphoneno values ('1-800-222-SAVE(7283)') --- Rule 2,4
    Insert into #myphoneno values ('(800) 111-4015') --Rule 3,4
    Insert into #myphoneno values ('18002288775') ---Rule 5
    Insert into #myphoneno values ('(800) 2223415')--- Rule 1,3,4,5
    Insert into #myphoneno values ('(800) 2-MOHAN')--- Rule 1,,3,4
    Insert into #myphoneno values ('1-800-228-4995') ---Rule 4
    Insert into #myphoneno values ('877-233-0112')---- Rule 1,4
    Insert into #myphoneno values ('800 228 3315')--- 1,3,4
    Insert into #myphoneno values ('18002284225')---Rule 5
    Insert into #myphoneno values ('800/219-1140') --- Rule 1,4
    Insert into #myphoneno values ('1 (855) ECO-8107') -- Rule 3,4
    Insert into #myphoneno values ('(888) BOM4BQC')-- Rule1,3,4
    Insert into #myphoneno values ('877-421K-MOX')-- Rule 1,4
    ;with mycte as(
    Select phone,
    replace(replace(replace(replace(replace( replace(phone,'(','.'),')','.'),'-','.'),'/','.'),' ','.'),'..','.') tmpCol
    from #myphoneno)
    ,mycte1 as (select phone, case when left(tmpCol,1)='1' then tmpCol else '1.'+tmpCol end tmpcol1 from mycte)
    select phone, Case when charindex('.', tmpcol1) >0 then left(replace(tmpcol1,'..','.') ,14) Else
    substring (tmpcol1,1,1)+'.'+ substring (tmpcol1,2,3)+'.'
    + substring(tmpcol1,5,3)+'.' +substring (tmpcol1,8,4) end as newPhone from mycte1
    drop table #myphoneno

  • How do I sort my phone numbers inside a contact? (using custom labels)

    Alright, since I've converted to iCloud, I'm now adding new contacts in there. However... before I was adding phone numbers through Address Book on my Macbook (that ended up creating a conflict with iCloud so I'm now using iCloud). What I want to know is... in address book you can set up a "default template" for your contacts (to include spouses, children, multiple addresses, phone numbers etc) I have created several labels for phone numbers, so I know which carrier they are since most of my contacts have 2-4 cell phones (all different carriers). Anyways, in address book I have for example ATT as the primary one on the list and then example: Verizon, Sprint, Tmobile & last the home phone). I have it set in that way, so even if someone only has ATT & Sprint, ATT will be at the top. Since I switched to iCloud (the carriers are all jumbled around in the contact and the reason I had placed them in a specific order is because I have one or two of those first carriers). Please let me know if you know how to change this in iCloud? Thanks!!!

    Fair enough.
    I started doing this before unlimited data and emails on phones was a common commodity, on my Samsung Blackjack.
    I then continued it due to its convenience. My only counter argument is this:
    Even when emails are set to immediately push, I am always notified earlier by this forwarding message (sometimes by several minutes/hours due to the fact that it is not dependent on my being connected to 4G or wifi to receive it.
    Also, to contradict snozdop's point that both methods use data and battery, I say this - when I use the forwarding method, the information comes in a pure text format and therefore uses considerably less information than an HTML and CSS rich email, with embedded images and such -also, unlimited text messages aids curve costs.
    I will, however, give this method a go. In any case, a solution to my original question would still be greatly appreciated.
    Thanks guys.

  • How do I back up phone numbers from Nokia 6350 bef...

    I got so tired of my buggy Nokia 6350 that I went to my service provider's website (AT&T) and bought an iPhone 3GS. When it arrived I read the instructions, found some confusing directions there and am in the process of asking for clarifications in the AT&T discussion forum.
    The reason I'm posting here is that my brother, who works at a cell phone call center, advised me to back up all my phone numbers from the Nokia before attempting this flip phone to smart phone transition. I have a USB cord that connects the Nokia to my PC, but Windows XP tries to "install the new hardware" and looks for a CD. I never got a CD with the Nokia. And I can't use the Ovi suite because -- just my luck -- the 6350 is one of the minority of phones not compatible with the Ovi suite.
    How do I back up all phone numbers before I attempt to copy them to the iPhone 3GS?  I'm very frustrated..
    Solved!
    Go to Solution.

    Download the pc suite instead of ovi suite. U'll find it under the support page of ur phone on Nokia's site
    Please mark the post as solution if it solves your problem.
    Current Device - Nokia Lumia 1020/920

  • How do I get facebook phone numbers into my iphone contacts list?

    I switched from a droid to an iPhone recently and with the droid all of my facebook contacts with phone numbers were synced into my phone and I can't figure out how to do that with my iPhone. I know that you can sync exsisting contacts with their facebook pictures, birthdays, etc but I want my facebook contacts into my phone without having to type in each number individually.

    See if this helps: http://www.iphonestuffs4u.com/how-to-sync-facebook-contacts-to-iphone/.

  • How to change format of OOB columns in sharepoint 2010?

    Hi,
    I have an requirement of changing of date format from 12/05/2014  to 12 May 2014 in a list for 2 Out of Box columns: Created , Modified. Can some one please help me on this.
    Please find the screenshot in which columns are highlighted:
    Badri

    Hi,
    Please check below:
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/ade1b4a2-7eac-479a-9dde-baa66eb18e36/how-to-change-date-format-of-sharepoint-list
    http://www.sharepointusecases.com/2009/01/customizing-datetime-format-on-a-list-view-web-part/
    Hope it helps!
    Thanks,
    Avni Bhatt

  • How to change format in iMovie 10?

    I've spent a lot of time trying to figure out how to change project settings to anything other than HD 1080. There doesn't seem to be any way to do change to SD. iMovie help doesn't mention it. Is this kind of like Numbers find and replace, a feature sort of there but not working? If there is a workaround to change to SD, including editing the project file in a hex editor, I'd love to hear it. Thanks.

    In iMovie 10 go to File>Share>File, choose the size (probably should choose either SD or Large) then click Next, give it a name, then click Save (remember where you saved it to).
    Wait until the Activity Indicator shows that the sharing process is complete.
    Go to iDVD. Go to File>Import>Video and select the file you created earlier. It will bring the video into your iDVD project. Prepare your DVD project and when you're ready, click the "Burn" button.
    iDVD is no longer officially supported by Apple, but it still works great.

  • HT1751 how do i recover my phone numbers from my iTunes bkup when i lost my phone

    how can i recover my contact phone numbers from my itunes backup of my iphone without the iphone.  I am trying to recover the phone numbers due to my losing my phone and not having recovered it.

    Your iphone is designed to be sycned to your computer regularly.  All of your contacts should be in whatever program you have chosen to sync ( Outlook or Address Book for example).

Maybe you are looking for

  • Script to Create Image on the Fore Edge of a Book

    Hello, Here is an example of what I want to do: http://blog.eyemagazine.com/?p=149 If you bend the pages of book, you can see an image (which is a word) on the fore edge of a book. I was wondering if there is a script or if I could create a script th

  • Send reminder 30 days before expire date?

    Hi, I hope someone can help me with that. I am getting in an "expireDate" from a Database. It can be for ex. "5/21/2007" . This date is a String. 30 days before that expireDate is reached, I want to send a reminder to the client, like "your membershi

  • Include external code with some protected way ?

    Hello, I would like to know, how it is possible to put C++ code into LabView with secure way. I tried it with creating .dll and in LabView call it with Call Library Function Node, but the .dll returns one value True or False and it is possible to cra

  • Enterprise Edition of Nokia PC Suite

    Hey, I wud like 2 share this one http://europe.nokia.com/find-products/nokia-for-business/managing Glad news for Enterprise Users If my post helped you, click on Kudos button and if my solution provided is opt 2 u, accpt my solution

  • Problems connecting NSU to my N73

    I have installed the latest version of NSU and it starts up fine i then follow all of the steps but it fails to detect my phone but my pc suite picks the phone up fine. Is anyone else having this problem or no how to fix this problem? Thanks