Reputation: 1904
I'm newbie for script. I am trying to create a powershell to take all my users in active directory and format all of their phone numbers the same + 90 (XXX) XXX XX XX
So an example - +901111111111
will turn to +90 (111) 111 11 11
Upvotes: 0
Views: 3430
Reputation: 7489
if your numbers are all the same length & pattern, then the -f
string format operator with a format pattern would do the job. [grin] like this ...
$InString = '+901111111111'
$OutPattern = '+## (###) ### ## ##'
$OutString = "{0:$OutPattern}" -f [int64]($InString.Trim('+'))
$OutString
output = +90 (111) 111 11 11
Upvotes: 5
Reputation: 5
Just in case all numbers have same length this quick solution could solve the problem
$input = "+901234567890"
$output = $input.Substring(0,3) +
" (" +
$input.Substring(3,3) +
") " +
$input.Substring(6,3) +
" " +
$input.Substring(9,2) +
" " +
$input.Substring(11,2)
# $output value should be "+90 (123) 456 78 90"
Upvotes: 1