Page 1 of 1

matching and displaying the new values using RegEx and PowerSHell?

Posted: Wed Nov 28, 2018 5:10 pm
by ITEngineer
Hi All,

I need to reformat the value of $ADUser

From: 0123456789
Into: +31 123456789

Without the leading 0 component.

The below snippet is what I have come up with, but it is still not working with the RegEx section to segregate the 0 section.

Code: Select all

$ADUser = '0123456789'

$(If ($ADUser) {
        If ($ADUser.ToString() -match '^([\+|0-9 ][ 0-9.]{1,12})$')
        { "+31 $($Matches['^([\+|0-9 ][ 0-9.]{1,12})$'])" }
        Else
        { $ADUser.ToString() }
    }
    Else { $ADUser.ToString() })
Any help would be greatly appreciated.

Thanks in advance,

Re: matching and displaying the new values using RegEx and PowerSHell?

Posted: Wed Nov 28, 2018 5:46 pm
by jvierra
Why so much code:

'+31 ' + '0123456789' -replace '^0'

Re: matching and displaying the new values using RegEx and PowerSHell?

Posted: Wed Nov 28, 2018 5:55 pm
by ITEngineer
jvierra wrote: Wed Nov 28, 2018 5:46 pm Why so much code:

'+31 ' + '0123456789' -replace '^0'
Yes, that works really well :)

This is part of the email signature script that I am working on.

Thanks for the suggestion Mr. Vierra