how to extract data from AD with VBS, and modify the output by adding spaces, brackets and a dash

Posted on 2014-07-17
Last Modified: 2014-07-21

i need a sub routine that will read a telephone number from AD and then modify the number by inserting spaces, brackets and dashes into the final output.
the final input is then used in our signature script.
script is working perfectly well i just need to make this small modification.

i think it would fairly simple to do but my vbs skills arent there yet... so im not really sure where to start and what commands i should be looking at.

so to sum things up

as you can see from this image, the phone number comes in the format +xxxxxxxxxxxx
Phone Number
i need this sub routine to modify the number into the following format

+xx (xx) xxxx-xxxx

once the sub has created this into a final output it will then be called by another Sub and entered into the section of the script that creates the signature.

the line in the script that will call on this is

SigFileStream.WriteLine " T " + g_objldapuser.telephoneNumber + " | " +" M " + + " | " + " F +xx xxxxxxxx "

Open in new window

id like to replace g_objldapuser.telephoneNumber with the final formatted output from the sub routine so it looks something like this.

SigFileStream.WriteLine " T " + sFormattedPhone + " | " +" M " + + " | " + " F +xx xxxxxxxx

Open in new window

i hope this makes sense...  does anybody have a script that does something like this?
or if you could guide me in the right direction that would be great..

please let me know if you need any more info.

Question by:BakerSyd
    LVL 65

    Accepted Solution

    Hi, this should work for you.



    sFormattedPhone = g_objldapuser.telephoneNumber
    sFormattedPhone = Left(sFormattedPhone, 3) & " (" & Mid(sFormattedPhone, 4, 2) & ") " & Mid(sFormattedPhone, 6, 4) & "-" & Right(sFormattedPhone, 4)
    SigFileStream.WriteLine " T " + sFormattedPhone + " | " +" M " + + " | " + " F +xx xxxxxxxx "

    Open in new window


    Author Closing Comment

    fantastic... does exactly what i need

    thanks Rob!
    LVL 65

    Expert Comment

    No problem. You had already done the legwork so my part was easy ;-)

    Thanks for the grade.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
    Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now