Remove +1 and parentheses from phone number

The code works fine:

$num = ($ADUser.TelephoneNumber).replace('+1 ', "")
$num = $num.replace('(',"")
$num = $num.replace(') ',"-")
$num

but I know that there is an easier way or I am doing something wrong. I am also fine using regex. I just need someone to help me

From AD: +1 (212) -*
I would like it this one: --****

Not sure if this is the correct solution but it’s a solution :slight_smile:

Just replace the right parenthesis and space with a dash and select the substring:

$num.replace(') ','-').Substring(4)

Another solution could be this:

“+1 (212) 234-5678” -replace ‘+1\s+((\d{3}))\s+(\d{3}-\d{4})’,‘$1-$2’

Thanks Matt it worked