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 (4.7k 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 (217k 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
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 (450 points)
0 votes
0 answers

I have created a Custom action to create some "standard" sub OUs to a particular type of OU in our AD. I wanted to create a script to look in the OU you are executing ... 'Users') -or ($child.Name -eq 'Computer Systems')) {$Context.ConditionIsMet = $False } }

asked Aug 31, 2016 by ggallaway (1.2k points)
0 votes
1 answer

I thought I would share this. We are new to Adaxes but really finding it a great tool to host some powershell scripts and make them accessible to others in the team without ... --------- If there are better ways to do this I am definitely interested.

asked Nov 29, 2018 by jbadry (1.7k points)
0 votes
1 answer

Hello - I have configured some custom property patterns for office location and Department and am seeing a drop down list when attempting to create a new user limited to the ... down list. Is this therefore only limited to some AD attributes and not others ?

asked Mar 21, 2017 by cdsouza (280 points)
0 votes
1 answer

Hello, We are experiencing the following issue: 1. Use Adaxes to Create a new user and mail enable the user. 2. try to use Adaxes to assign Send As rights to ... Send As permssion using the Exchange console if the account was created in Adaxes. Please help.

asked Aug 12, 2013 by DFassett (4k points)
2,352 questions
2,106 answers
5,746 comments
126,792 users