Skip to content

Instantly share code, notes, and snippets.

@Warsaalk
Last active February 4, 2021 00:07
Show Gist options
  • Save Warsaalk/958ed29ead5dfaa28132a2a97fc9a5ed to your computer and use it in GitHub Desktop.
Save Warsaalk/958ed29ead5dfaa28132a2a97fc9a5ed to your computer and use it in GitHub Desktop.
Outlook signature distribution logon script - Template
' Global variables
Set objShell = CreateObject("WScript.Shell")
Set objUser = CreateObject("ADSystemInfo")
Set objCurrentUser = GetObject("LDAP://" & objUser.UserName)
' Outlook signature location, for Outlook 2010, 2013 & 2016
appData = objShell.ExpandEnvironmentStrings("%APPDATA%")
outlookSignatures = appData & "\Microsoft\Signatures"
' Signature locations
source = "\\[sharename]\signatures"
sourceSig = source & "\[signaturefilename].htm"
destinationSig = outlookSignatures & "\[signaturefilename].htm"
processSig = False
Set fso = CreateObject("Scripting.FileSystemObject")
'Create missing folders
If Not fso.FolderExists(outlookSignatures) Then
fso.CreateFolder(outlookSignatures)
End If
' Copy the source signature if it doesn't exist
If Not fso.FileExists(destinationSig) Then
fso.CopyFile sourceSig, destinationSig, True
processSig = True
End If
' Copy a logo (could come in handy)
If Not fso.FolderExists(outlookSignatures & "\img") Then
fso.CreateFolder(outlookSignatures & "\img")
End If
If Not fso.FileExists(outlookSignatures & "\img\logo.png") Then
fso.CopyFile source & "\img\logo.png", outlookSignatures & "\img\logo.png", True
End If
' Update destination signature if the source was modified
Set sourceFile = fso.GetFile(sourceSig)
Set destinationFile = fso.GetFile(destinationSig)
If sourceFile.DateLastModified > destinationFile.DateLastModified Then
fso.CopyFile sourceSig, destinationSig, True
processSig = True
End If
' If we need to process the signature let's build it
If processSig Then
Set desinationFileContent = fso.OpenTextFile(destinationSig, 1)
signatureContent = desinationFileContent.ReadAll
desinationFileContent.Close
' Replace the available placeholders (Format: %%placeholder%%)
signatureContent = Replace(signatureContent, "%%FirstName%%", objCurrentUser.FirstName)
signatureContent = Replace(signatureContent, "%%LastName%%", objCurrentUser.LastName)
signatureContent = Replace(signatureContent, "%%Title%%", objCurrentUser.Title)
signatureContent = Replace(signatureContent, "%%PhoneNumber%%", objCurrentUser.TelephoneNumber)
signatureContent = Replace(signatureContent, "%%MobileNumber%%", objCurrentUser.Mobile)
signatureContent = Replace(signatureContent, "%%Email%%", objCurrentUser.Mail)
Set desinationFileContent = fso.OpenTextFile(destinationSig, 2)
desinationFileContent.WriteLine signatureContent
desinationFileContent.Close
' Message to notify the user (uncomment the line below to activate)
' WScript.Echo "Your Outlook signature [name] has been updated."
End If
@Warsaalk
Copy link
Author

Warsaalk commented Jul 11, 2016

Setup:
Client: Windows 7 & Windows 10 with Outlook 2016 (inside a company domain)
Server: Windows Server 2008 R2 (using a logon script in a Group Policy)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment