Need to Manipulate Phone Number

Good day all -

Following this blog here (http://blogs.technet.com/b/nexthop/archive/2011/02/01/howtoadphonetolineuri.aspx)  to manipulate phone number is our AD organization. Unfortunately when Lync populates the contact field from AD it looks at the Telephone Number and Office Number. In our organization these numbers are reversed. Meaning, the 10 digit number is xxx.xxx.xxxx is listed in the "Office" field of AD and the 4 Digit Extension is listed in the "Phone". With that said, we do have have different calling blocks. Meaning must of our numbers are:

555.555.9xxx

and 555.556.6xxx

All internal extensions (listed in the Telephone number field) begin with 5 and would be replaced with the last xxx in the above example.

So for the 555.250.9xxx block would be 200-499 .... for example extension 5394 would be Direct Dial Number 555.555.9394

And for the 555.556.6xxx block would be 600-799 ...  for example extension 5657 would be  Direct Dial Number 555-555.6657

So my question is this...with the above - how can I populate the below script correctly? Thanks for helping out.

$enabledUsers = Get-CsAdUser -Filter {Enabled -ne $Null}

foreach ($user in $enabledUsers)

    {

        $phoneNumber = $user.Phone

        $phoneNumber = $phoneNumber -replace "[^0-9]"

        $extension = $phoneNumber -match "^5"

        if ($extension)

            {

                $phoneNumber = "TEL:+120655" + $phoneNumber

            }

        else

            {

                $phoneNumber = "TEL:+142556" + $phoneNumber

            }

      

        Set-CsUser -Identity $user.Identity -LineUri $phoneNumber

    }

February 23rd, 2015 7:30pm

Hi Sir,

>>

In our organization these numbers are reversed. Meaning, the 10 digit number is xxx.xxx.xxxx is listed in the "Office" field of AD and the 4 Digit Extension is listed in the "Phone". With that said, we do have have different calling blocks. Meaning must of our numbers are:

555.555.9xxx

and 555.556.6xxx

 

Based on my understanding , you are going to get a number from "Phone" such as 555.555.9xxx and get a 4 digit extention number . Then you want to get the latest three number of the "Extention" number then replace "xxx" to get a direct dial number and save it into AD .

Do you mean the "Office" field and "Phone" field  are  "Office" and "Telephone number" in AD user properties :

I would suggest you to use The method substring() to cut and connect the number .

E.g. If you want to cut the  first three number  of 123456 the command may:

$a="123456"

$a.substring(0,3)

Best Regards,

El

Free Windows Admin Tool Kit Click here and download it now
February 25th, 2015 4:01pm

Hi Sir,

I would like to check the current state of this issue .

Best Regards,

Elton Ji

March 9th, 2015 11:17am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics