0 votes

I've adapted a RegEx to normalize phone numbers, source: http://www.regexplanet.com/cookbook/pho ... index.html.

Import-Module Adaxes
$identity = "%sAMAccountName%"
$mobileNumber = '%mobile%' -ireplace '\D*([2-9]\d{2})(\D*)([2-9]\d{2})(\D*)(\d{4})\D*', '+1 ($1) $3-$5'
Set-AdmUser -Identity $identity -MobilePhone "$mobileNumber"

Testing in the Powershell IDE works perfectly on all phone numbers I gave it. However, when running on numbers formatted at +1 (888) 555-5555, adaxes returned +1+1 (888) 555-5555.

Any guidance on this?

by (1.2k points)
0

I fixed the problem by escaping the input with:

see below.

0

Spoke before I actually tested in adaxes...

The function works once you move the escape to the input as follows:

Import-Module Adaxes  

$identity = "%sAMAccountName%"  

$mobileNumber = \[Regex\]::Escape('%mobile%') -ireplace '\\D\*(\[2-9\]\\d{2})(\\D\*)(\[2-9\]\\d{2})(\\D\*)(\\d{4})\\D\*', '+1 ($1) $3-$5'  
Set-AdmUser -Identity $identity -MobilePhone "$mobileNumber"

If anyone has any suggestions on improving efficiencies, please post.

Thanks!

1 Answer

0 votes
by (216k points)
selected by
Best answer

Hello,

The thing is that \D* (non-digits) doesn't include a sequence of characters that contain a plus (+) sign. So, to resolve your issue, you simply need to replace the starting and ending \D* with .* (matches any character). In this case, your zero-level character class will include all characters in the string. The resulting regular expression is as follows:

.*([2-9]\d{2})(\D*)([2-9]\d{2})(\D*)(\d{4}).*

In this case, you don't need to escape anything, just call -ireplace on the value returned by %mobile%:

Import-Module Adaxes

$identity = "%sAMAccountName%"

$mobileNumber = '%mobile%' -ireplace '.*([2-9]\d{2})(\D*)([2-9]\d{2})(\D*)(\d{4}).*', '+1 ($1) $3-$5'
Set-AdmUser -Identity $identity -MobilePhone "$mobileNumber"

Related questions

0 votes
1 answer

Hi team, we have two accounts for Adaxes in our AD Service account (running services) named "service-adaxes" Service Domain account (to connect to AD) named "service-adaxesdomain" ... script? Or do I need to grant permissions to "service-adaxes" to manage AD?

asked Jul 30 by wintec01 (1.5k points)
0 votes
1 answer

Hello I'm trying to run a custom PowerShell script to request a Workspace ONE Access Sync when I change something in our users or groups. Here is the script: $ClientId = "api ... of having to create 6 independent rules with each of them a copy of the script)?

asked Sep 25, 2021 by ygini (240 points)
0 votes
0 answers

We have an inactive user task which runs daily that disables accounts after 30 days of inactivity. We had an example yesterday of a user account which had been disabled ... Are you able to provide any explanation of how this could have happened? Regards Andy

asked Sep 12, 2017 by Andy_W (40 points)
0 votes
1 answer

In a business rule, I'd like to pass Adaxes variables into a powershell script that I'll run. For example, pass %username% into the script so it can be used inside the script.

asked Sep 5 by P-Sysadmin (20 points)
0 votes
1 answer

Hello Adaxes Support, I couldn't find a script to enable MessageCopyForSentAsEnabled for a shared mailbox, do you have a script for me to do that?

asked May 22 by dominik.stawny (280 points)
3,564 questions
3,255 answers
8,264 comments
547,914 users