Active Directory Outlook Signature – VBS script

Setting up an email signature for each Outlook user in the organization can be a time consuming job, especially when performed manually. Moreover – every time a change in the signature is required the whole process needs to be repeated.

That is why system administrators are searching the web for a more centralized way of performing this task. One of the possible solutions is to run a logon script, distributed to workstations via the Group Policy Object. When the end user logs on the script gathers information about that particular person from Active Directory and creates a personalized email signature in Outlook. Below you will find a guide how to configure such script.

Script preparation

Firstly you need a VBS script that creates a signature in Outlook. Below you can find an example code, that reads user’s information from Active Directory. That information is then inserted into the signature. Lastly, the script sets the signature to be added in new emails and reply emails.

On Error Resume Next

Set objSysInfo = CreateObject("ADInformation")

strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
If objUser Is Empty Then _
MsgBox "No connection with LDAP information.", _
vbCritical, "Error": Exit Sub

strName = objUser.FullName
strTitle = objUser.Title
strDepartment = objUser.Department
strCompany = objUser.Company
strPhone = objUser.telephoneNumber

Set objWord = CreateObject("Word.Application")

Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection

Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSignature

Set objSignatureEntries = objSignatureObject.EmailSignatureEntries

' Beginning of signature block

objSelection.TypeText strName & ", " & strTitle
objSelection.TypeParagraph()
objSelection.TypeText strDepartment
objSelection.TypeParagraph()
objSelection.TypeText strCompany
objSelection.TypeParagraph()
objSelection.TypeText strPhone

' End of signature block

Set objSelection = objDoc.Range()

objSignatureEntries.Add "AD Signature", objSelection
objSignatureObject.NewMessageSignature = "AD Signature"
objSignatureObject.ReplyMessageSignature = "AD Signature"

objDoc.Saved = True
objWord.Quit

Simply copy the above text into any plain text editor (e.g. Windows Notepad) and save it with the VBS file extension.

To test the script execute it on a workstation with Outlook installed (make sure that Outlook is not running). Next time you launch Outlook and create a new message it should contain a signature, similar to the example below:

2vb

To modify the signature change the code between ‘ Beginning of signature block and ‘ End of signature block in the script. Let’s say you need to add user’s email address at the very end of the signature. You can do this by adding the following line in the signature block of the script:

objSelection.TypeParagraph()
objSelection.TypeText strEmail

The resulting signature block in the script is as follows:

' Beginning of signature block

objSelection.TypeText strName & ", " & strTitle
objSelection.TypeParagraph()
objSelection.TypeText strDepartment
objSelection.TypeParagraph()
objSelection.TypeText strCompany
objSelection.TypeParagraph()
objSelection.TypeText strPhone
objSelection.TypeParagraph()
objSelection.TypeText strEmail

' End of signature block

To enter any string of text that is not dynamically gathered from Active Directory, simply replace the placeholder part of the objSelection.TypeText command (e.g. strEmail) with a text placed between the quotation marks. In the example below the environmental disclaimer is added:

' Beginning of signature block

objSelection.TypeText strName & ", " & strTitle
objSelection.TypeParagraph()
objSelection.TypeText strDepartment
objSelection.TypeParagraph()
objSelection.TypeText strCompany
objSelection.TypeParagraph()
objSelection.TypeText strPhone
objSelection.TypeParagraph()
objSelection.TypeText strEmail
objSelection.TypeParagraph()
objSelection.TypeText "Please consider the environment before printing this message."

' End of signature block

Distributing the signature via GPO

To distribute the script automatically to all workstations in the organization the easies way is to use the GPO policy. This method will provide every single user with the signature when they log on into their computer.

To begin log on to your server and click the Start menu button, then select Administrative Tools menu and click Group Policy Management. Alternatively you can run the gpmc.msc command in the Start menu search field. This opens the main GPO console window:

1vb

In the left pane expand the branch with your server name, then expand Group Policy Objects. Next right-click the Default Domain Policy object select Edit.

3vb

In the Group Policy Management Editor navigate to User Configuration in the left pane, then go to: Policies, Windows Settings, Scripts (Logon/Logoff).

4vb

Next, double click the Logon option visible in the right pane which launches the Logon Properties window. Then click the Show Files… button to open the folder containing scripts. Copy your VBS script into that folder. Next, in the Logon Properties window click the Add… button and select the script file that you just copied in by clicking the Browse… button.

5vb

Save the settings by clicking the OK button all the way down.

That’s it – next time your users login on their workstations the script will launch and create the Outlook signature that contains user’s AD information.

This method is fairly useful, however it has a couple of drawbacks:

  • Users can modify their signatures before sending which might breach the unified signature look regulation.
  • Every change in the signature requires all users to log off and log back on to re-run the script and apply changes.
  • Signature editing is quite complicated and requires a bit of programming knowledge.
  • Administrative access to the server is required.

Fortunately there are more user friendly solutions, such as CodeTwo Exchange Rules or CodeTwo Exchange Rules Pro. They not only overcome all above limitations, but also deliver much more:

Easy to use GUI that lets you create any kind of signature in a friendly way;

  • A signature testing facility allows to check and see how your signature template looks like before deploying it to the live environment;
  • It supports all emails processed by the Exchange transport service, no matter from what email client they were sent by the end user;
  • The program provides a remote access to the signature deployment. This way the process can be delegated to e.g. your marketing team without giving them direct access to the server;
  • A rich library of ready to use signature templates is available;
  • All email formats are supported – no matter it’s HTML, Plain Text, or RTF;
  • You can download and use the fully functional program for 30 days to see if it suit your needs.
  • And more.
Active Directory Outlook Signature – VBS script by

10 thoughts on “Active Directory Outlook Signature – VBS script


    • Hi Ali,

      Just substitute the ‘Please consider the environment before printing this message.’ part with whatever you want your disclaimer to say.

      Hope this helps,
      Adam

  1. I you do not have strPhone or strMobile for example, you should use IF() finction.

    If Len(Trim(strPhone)) > 0 Then strPhone = “Ph. ” & strPhone & ” | ”
    If Len(Trim(strMobile)) > 0 Then strMobile = “Mob. ” & strMobile & ” | ”
    objSelection.TypeText strPhone & strMobile

  2. Hi Adam,
    Thanks for the script. It works for me. I am very new in scripting and would like to know how to insert a line if the AD field is null. For example if a user does not have a mobile number. Please see my script below.

    On Error Resume Next

    Set objSysInfo = CreateObject(“ADSystemInfo”)

    strUser = objSysInfo.UserName
    Set objUser = GetObject(“LDAP://” & strUser)

    strName = objUser.FullName
    strTitle = objUser.Title
    strCompany = objUser.Company
    strPhone = objUser.telephoneNumber
    strMobile = objUser.Mobile

    Set objWord = CreateObject(“Word.Application”)

    Set objDoc = objWord.Documents.Add()
    Set objSelection = objWord.Selection

    Set objEmailOptions = objWord.EmailOptions
    Set objSignatureObject = objEmailOptions.EmailSignature

    Set objSignatureEntries = objSignatureObject.EmailSignatureEntries

    objSelection.Style = “No Spacing”
    ‘objSelection.Font.Name = “Tahoma”
    ‘objSelection.Font.Size = “14”
    objSelection.TypeText strName & vbLF
    objSelection.Font.Color = RGB(190,190,190)
    objSelection.TypeText strTitle & ” | ”
    objSelection.Font.Color = RGB(0,0,0)
    objSelection.Font.Underline = True
    objSelection.Font.Bold = true
    objselection.TypeText strCompany
    objSelection.TypeParagraph()
    objSelection.Font.Underline = false
    objSelection.Font.Bold = false
    objSelection.TypeText “Ph. ” & strPhone & ” | ” & “Mob. ” & strMobile & ” | ”

    Set objSelection = objDoc.Range()

    objSignatureEntries.Add “AD Signature”, objSelection
    objSignatureObject.NewMessageSignature = “AD Signature”
    objSignatureObject.ReplyMessageSignature = “AD Signature”

    objDoc.Saved = True
    objWord.Quit

  3. @Andreas, you’ve get single comma, because you have no connections with LDAP.
    Your signature use strName & “, ” & strTitle when strName and strTitle is a empty string (as the rest of it).

    You can add this linle after Set objUsr …
    If objUser Is Empty Then Exit Sub

  4. Hi,

    I tried your script example and it is added in outlook signatures.
    Now all I get is a comma. What do you think is wrong here?

    Thanks,
    Andreas

  5. Hi Adam

    Quick question:

    I tried using your script and it pretty much works for me. But I don’t want the paragraphs so I deleted them. Afterwards I executed the vbs again but the paragraphs are still there..

    I can’t fix this with either vbCrLf nor vbCR or vbLf..

    Do you have an idea?

    Kind regards
    Marcel

    • Hi Marcel,

      Sorry for the late reply.

      Do I understand correctly that instead of paragraphs you want single line breaks (such as you would get by pressing shift+enter)? If so, please try using this code:

      ' Beginning of signature block

      objSelection.TypeText strName & ", " & strTitle & Chr(11)
      objSelection.TypeText strDepartment & Chr(11)
      objSelection.TypeText strCompany & Chr(11)
      objSelection.TypeText strPhone

      ' End of signature block

      If I misunderstood your intention, please post an image of what you would like your signature to look like, or try to convey it in the comments.

      Thank you!
      Adam

Leave a Reply

Your email address will not be published.

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>