Adding a leading +1 to all office phone numbers

Welcome Forums General PowerShell Q&A Adding a leading +1 to all office phone numbers

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
3 months, 3 weeks ago.

  • Author
    Posts
  • #105368

    Participant
    Points: 0
    Rank: Member

    I have a script to input the office phone numbers after I strip all off the items not needed like ( ), +, or -.
    After that I'd like to simply add a +1 to the beginning of each phone number. Right now this is what I have to do the formatting and removal that spits out the phone number in a 9 digit format which is perfect. Just that last final leading +1 at the beginning i'm stuck on.

    
      #Formats Removes Symbols and spaces from the telephone number
                    $teltemp = $employee.'Business_Phone'.Trim().Replace('/','').Replace('-','').Replace('   ','').Replace('  ','').Replace(' ','').Replace('+','')
    				
    				
                    #Remove any leading 1 from the telephone (10 digit to 9 digit)
                    $telephone =  $teltemp  #-Replace '^1',''          
    
    

    Any suggestions? I'd like to keep this as straight forward and simple as possible.

    thanks,

  • #105371

    Participant
    Points: 160
    Helping Hand
    Rank: Participant

    You can look at examples of string concantenation, but this is a string format:

    $telTemp = "5551234567"
    
    $telTemp = '+1{0}' -f $telTemp
    
    $telTemp
    
  • #105373

    Participant
    Points: 0
    Rank: Member

    I think that did it! I was super close! 😀 LOL...part I missed was location of the brackets.

    I was testing with {+10} -f $teltemp both with single and double quotes.

    Thanks a lot!! Easy one huh? :))

The topic ‘Adding a leading +1 to all office phone numbers’ is closed to new replies.