dimanche 28 février 2021

Replace phone numbres

I have a list that contains phonenumbers with different formats. Ex.

  • 08542564782
  • 08 25 45 21 45 4
  • +185472654014
  • +1 8547562154
  • +1085458754856

I'm trying to replace the numbers using "-replace"

If ($User.mobilePhone.StartsWith("08")) {

    $AM = $User.mobilePhone -replace "^08", "+1 8"

}

If ($User.mobilePhone.StartsWith("+18")) {

    $AM = $User.mobilePhone -replace "^\+18", "+1 8"

}

If ($User.mobilePhone.StartsWith("+1 08")) {

    $AM = $User.mobilePhone -replace "^\+1 08", "+1 8"

}

After replacing the numbers, I want to compre them to a diffrent list with the same numbers but correct format. EX.

  • +1 8542564784
  • +1 8254521455
  • +1 8547265401
  • +1 8547562154
  • +1 8545875485
if ($test -ne $AM) {
    
    write-host "The number is not equal'

}

The IF statement should be false but for some reason it's true.

Aucun commentaire:

Enregistrer un commentaire