Scripted Active Directory Outlook Users Signatures

10 Mar

So I need to get all the employee’s signatures to look the same and all the information needs to be up to date. Creating each users signature manually is a bit of hard work, getting them to keep it up to date is a nice idea, but it simply wouldn’t happen, and I would just end up spending a lot of my time explaining how to change it.

Another option was to have our intranet (in ASP.net), which holds all the users details generate the users signature (you could also use an LDAP query against AD) on a web page, they could then copy and past that into Outlook, but again, this is a manual procedure, and so probably wouldn’t happen in the long term. There were a few commercial options, but I didn’t have the budget for that, so I didn’t really look into it in any great detail.

I ended up looking at a VB script that would run at login and auto create the users signature based on their details at that point in time. The script then sets this newly created signature as the users default signature. I also created a small company logo gif and made that part of the signature. The script is obviously free, and works very well. Each time a users details change, I update AD, so next time they login they have an up to date signature. It also helps make sure that AD is correct and up to date.

The script is rolled out to all users via the group policy (Login script) and the logo is stored on the network. The script only works for Outlook users, and currently the only way for users using OWA to get the signature is to manually enter it, but as almost all our main users are using Outlook, this isn’t such an issue for me.

So, here’s the script, it’s all pretty straight forward stuff. I’ve omitted a few details, just to be on the safe side:

On Error Resume Next
Set objSysInfo = CreateObject(“ADSystemInfo”)
strUser = objSysInfo.UserName
Set objUser = GetObject(“LDAP://” & strUser)

‘Set variables

    ‘Name
    if (len(objUser.FullName) < 1) then
        strName = “”
    else
        strName = objUser.FullName
    end if

    ‘Title
    if (len(objUser.Title) < 2) then
        strTitle = “”
    else
        strTitle = objUser.Title
    end if

    ‘Company
    if (len(objUser.physicalDeliveryOfficeName) < 2) then
        strCompany = “”
    else
        strCompany = objUser.physicalDeliveryOfficeName
    end if

    ‘Address
    if (len(objUser.streetAddress) < 2) then
        strAddress = “”
    else
        strAddress = objUser.streetAddress
    end if

    ‘County
    if (len(objUser.st) < 2) then
        strCounty = “”
    else
        strCounty = objUser.st
    end if

    ‘City
    if (len(objUser.l) < 2) then
        strCity = “”
    else
        strCity = objUser.l
    end if

    ‘Postcode
    if (len(objUser.postalCode) < 2) then
        strPostcode = “”
    else
        strPostcode = objUser.postalCode
    end if

    ‘Fax
    if (len(objUser.faxnumber) < 2) then
        strFax = “”
    else
        strFax = “Fax ” & objUser.faxnumber
    end if

    ‘Mobile
    if (len(objUser.mobile) < 2) then
        strMobile = “”
    else
        strMobile = “Mobile ” & objUser.mobile
    end if

    ‘Email
    if (len(objUser.mail) < 2) then
        strEmail = “”
    else
        strEmail = “Email ” & objUser.mail
    end if

    ‘Web
    if (len(objUser.wwwhomepage) < 2) then
        strHomepage = “”
    else
        strHomepage = objUser.wwwhomepage
    end if

    ‘Telephone
    if (len(objUser.telephoneNumber) < 2) then
        strPhone = “”
    else
        strPhone = “Telephone ” & objUser.telephoneNumber
    end if

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

‘D Harris
‘Outlook Signature Generator
’10/03/2010
‘dave.harris@dore.co.uk

objSelection.Style = “No Spacing”

objSelection.Paragraphs.Alignment = wdAlignParagraphLeft

‘Double line break
objSelection.TypeParagraph()
objSelection.TypeParagraph()

‘Name then title
objSelection.Font.Size = “9”
‘Set the color in RGB below, I’ve removed our corporate colors
objSelection.Font.Color = RGB(0,0,0)
objSelection.Font.Name = “Arial”
objSelection.Font.Bold = true
objSelection.TypeText strName
objSelection.TypeParagraph()
objSelection.Font.Size = “8”
objSelection.Font.Name = “Arial”
objSelection.Font.Bold = false
objSelection.TypeText strTitle

‘Double line break
objSelection.TypeParagraph()
objSelection.TypeParagraph()

‘Add Logo
objShape = objSelection.InlineShapes.AddPicture(“\\SERVER\emaillogo\dorelogo.gif”)

‘line break
objSelection.TypeParagraph()
objSelection.TypeParagraph()

if (strMobile <> “”) then
    objSelection.TypeText strMobile
    objSelection.TypeParagraph()
end if
if (strPhone <> “”) then
    objSelection.TypeText strPhone
    objSelection.TypeParagraph()
end if
if (strFax <> “”) then
    objSelection.TypeText strFax
    objSelection.TypeParagraph()
end if
if (strEmail <> “”) then
    objSelection.TypeText strEmail
    objSelection.TypeParagraph()
end if

‘line break
objSelection.TypeParagraph()

objSelection.Font.Bold = true
objSelection.TypeText strCompany
objSelection.Font.Bold = false
objSelection.TypeParagraph()
objSelection.TypeText strAddress
objSelection.TypeParagraph()
objSelection.TypeText strCity
objSelection.TypeParagraph()
objSelection.TypeText strCounty & ” ” & strPostcode
objSelection.TypeParagraph()

‘line break
objSelection.TypeParagraph()

objSelection.Font.Bold = true
objSelection.TypeText strHomepage
objSelection.Font.Bold = false
objSelection.TypeParagraph()

‘Add signature to email
Set objSelection = objDoc.Range()
objSignature = objSignatureEntries.Add(“My Signature”, objSelection)

‘Set as default signature in Outlook
objSignatureObject.NewMessageSignature = “My Signature”
objSignatureObject.ReplyMessageSignature = “MySignature”
objDoc.Saved = True

‘Finish
objWord.Quit

That’s it. And the end result, should look something like this:

Update…

Work recently decided they then also wanted Facebook, Twitter, YouTube, RSS and Email logos in there which would hyperlink to those sites. I obtained the actaul logs from here and there is an M$ article on the scripting here. My code now includes this at the bottom:

‘Add Additional Logos & Links
objSelection.TypeParagraph()

sFacebookPicFile = “\\path\facebook.gif”
sFacebookLinkFile = “http://www.facebook.com/doreuk”

Set objShape1 = objSelection.InlineShapes.AddPicture(sFacebookPicFile, True)
objDoc.Hyperlinks.Add objShape1.Range, sFacebookLinkFile

objSelection.TypeText ” “

sTwitterPicFile = “\\path\twitter.gif”
sTwitterLinkFile = “http://twitter.com/doreuk”

Set objShape1 = objSelection.InlineShapes.AddPicture(sTwitterPicFile, True)
objDoc.Hyperlinks.Add objShape1.Range, sTwitterLinkFile

objSelection.TypeText ” “

sYoutubePicFile = “\\path\youtube.gif”
sYoutubeLinkFile = “http://www.youtube.com/DoreProgramme”

Set objShape1 = objSelection.InlineShapes.AddPicture(sYoutubePicFile, True)
objDoc.Hyperlinks.Add objShape1.Range, sYoutubeLinkFile
objSelection.TypeText ” “

sFeedPicFile = “\\path\feed.gif”
sFeedLinkFile = “http://www.dore.co.uk/rss.ashx”

Set objShape1 = objSelection.InlineShapes.AddPicture(sFeedPicFile, True)
objDoc.Hyperlinks.Add objShape1.Range, sFeedLinkFile
objSelection.TypeText ” “

sEmailPicFile = “\\path\email.gif”
sEmailLinkFile = “mailto:” & objUser.mail

Set objShape1 = objSelection.InlineShapes.AddPicture(sEmailPicFile, True)
objDoc.Hyperlinks.Add objShape1.Range, sEmailLinkFile

Whilst I was at it, I also hyperlinked the main corporate logo at the top of the signature.

So, the updated signature now looks like this: