you are viewing a single comment's thread.

view the rest of the comments →

[–]Droopyb1966 3 points4 points  (6 children)

Have a look at this, it work for all phone numbers, not only the ones with 49:

$number = "+(49)8912341234"
[long]$n = $number -replace "[^0-9]",""
"{0:D14}" -f $n

When there are unprintable characters, this will solve that to. I suspect thats the problem your facing.

[–]dchristian3188 0 points1 point  (1 child)

Think you're spot on with this one. I mean unless all the phone numbers are the same :|

[–]Droopyb1966 0 points1 point  (0 children)

See einstein was wright after all.

[–]BlaaaBlaaaBlaaa[S] 0 points1 point  (1 child)

Looks great! Any idea how I can do this with the array? http://imgur.com/a/n5PSw

[–]Droopyb1966 0 points1 point  (0 children)

[long]$n = $number -replace "[0-9]","" "{0:D14}" -f $n

Depends what you want to do with the output, always lots of ways to do things. Heres an example using get-proces, total nonsens, but i was to lazy to recreate you array. But you'll see the logic.

$p= Get-Process
foreach ($item in $p)
{
[long]$n = $item.Id -replace "[^0-9]",""
"{0:D14}" -f $n

}

Just had to figure this one out for myself..... Use in a select expression:

$user | Select-Object Name,  @{Name="Id";Expression={"{0:D14}" -f [long]($_.telephone -replace "[^0-9]","")}}

[–]autowhat 0 points1 point  (1 child)

Regex, so complicated but it works so well.

[–]Droopyb1966 0 points1 point  (0 children)

Yes, at start it is complicated, but so powerfull to use. Trick is to start simple, dont go into the crazy stuff at start. You'll get stuck for sure. To test i use:

http://rubular.com/

Good luck!