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, they gather 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 VBScript 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 to 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.QuitSimply 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:
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 easiest 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:
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.
In the Group Policy Management Editor navigate to User Configuration in the left pane, then go to: Policies, Windows Settings, Scripts (Logon/Logoff).
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 VBScript 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.
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.









Is Exchange required for this to work? I tried on a local setup and after working on the suggested script getting no errors I tried it from the workstation and the server and did not get any signature. Am at a loss here. strName and strTitle where are these values from are they the users info in Group Policys??
could you add a graphic or background color?
In the current form of the script, it is not possible to add graphics or background colors. However, you can use transport rules to add an HTML email signature (with colors and graphics). Here is a guide on how to do that: Email Signatures on Exchange
Will this code work if the users AD account contains a number as part of his ID. example “john.smith2”?
Hello Eddie,
The number should not have any influence on if and how the script works.
Hallo Adam,
I got also “No connection with LDAP information” (Windows 10.1607)
Your comment is that this is environment related.
But whatever could this be?
Kind Regards
Ronald
Hello Ronald,
I have just tested this script on a Windows 10 machine and I get the error as well. The issue is incredibly weird, as when I delete the If statement:
If objUser Is Empty Then _MsgBox "No connection with LDAP information.", _
vbCritical, "Error": Exit Sub
The signature appears without any problems, which means that the objUser is not empty.
Please try deleting the if statement to see if the script adds the signature correctly. If not – it means that the machine cannot connect with the LDAP correctly.
Dear Adam,
could you please provide me your email address?
i need some help on signatures by gp.
Thank you.
Hi, I have the same issue as Andreas. All I get is a comma. When I add “If objUser Is Empty Then Exit Sub” I have this error message : “Instruction ‘exit’ incorrecte’.
Can you help me please ?
hi.. im did your script work with oulook 2013 office 365 ?
I have not tested the script on Outlook 2013, but it should work. The problem is that, as it gets users’ data from the on-premises Active Directory, it will not be able to get any information from Office 365.
If you want to create automatic email signatures in Office 365, you might be better off creating a mail flow rule. You can see how to do this in this article: How to create company-wide email signatures and disclaimers in Office 365.
Hi Adam
Does the gpo method work for mac outlook 2016 (we were able to do it to mac outlook 2011), as we are having issue creating the default html signature for each user on mac 2016, as the mac outlook 2016 have move the signature location on the local drive.
Unfortunately, I am afraid you would need a third party tool to solve the problem. Have you considered adding email signatures on the server level? They would work on emails sent from any email client.
Hi
Thank you for the code and explanation.
I have tried this however getting an error ‘invalid exit statement’ on line 9.
Can you please assist
Thank you
Hi Nisha,
Try substituting Exit Sub with WScript.Quit (1).
Best regards,
Adam
Hi Adam
i am trying your script, its shows No connection with LDAP information
Hi Mabd,
Are you able to run LDAP queries (https://technet.microsoft.com/en-us/library/aa996205(v=exchg.65).aspx) from the problem machine?
-Adam
Make sure your logged on username matches the UPN in AD
does this script work with Windows 10 build 1709?
i keep getting that “No connection with LDAP information” whether i log in with UPN or with samAccountName/alias for the username.
The script should work in Windows 10. Most likely, your problem is environment-related.
Great post. I want to add a disclaimer at the bottom of every signature. How do I do that?
Cheers
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
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
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
@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
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
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