Blog

Automating Outlook Email Signatures on Windows

10/10/2024 3 min read

Automating email signatures is particularly challenging for small and medium-sized businesses. Often, these companies choose to manage signatures manually, which frequently leads to errors during the setup of new users or results in the signature being completely forgotten. Searching for a solution for easy automation often reveals that while many tools exist, they are usually paid—and often on an annual subscription basis. In such cases, it can be worthwhile to invest a few hours developing your own PowerShell script. Today, I want to show you an approach for such a script.


In my opinion, the simplest way to achieve this is with a logon script distributed via Group Policy that copies the signature from a central network share into the Outlook directory each time the computer starts. This is especially useful when signatures change occasionally, such as special signatures for Christmas or if an employee changes positions. Therefore, the first thing we need is a script that creates signatures for each employee and stores them on a central network share.

# Imports the Active Directory module to access AD objects.
Import-Module ActiveDirectory

# Retrieves details of all users from Active Directory, including first name, last name, and title.
$users = Get-ADUser -Filter * -Properties GivenName, Surname, Title

# Defines the URL of the company logo to be used in the email signature.
$logoUrl = 'http://beispiel.com/logo.png'

# Specifies the path where the generated email signatures will be saved.
$signatureDirectory = ""

# Iterates through each user in Active Directory.
ForEach ($user in $users) {
    # Extract first name, last name, and full name of the user.
    $firstName = $user.GivenName
    $lastName = $user.Surname
    $fullName = "$firstName $lastName"

    # Extracts the user's position/title.
    $position = $user.Title

    # Creates an HTML-based email signature including user details and company logo.
    $emailSignature = @"

    
        **$fullName**

        $position

        

    

"@

    # Generates the filename for the email signature based on the username.
    $fileName = "$signatureDirectory\$($user.SamAccountName).htm"

    # Saves the email signature to a file in the specified directory.
    $emailSignature | Out-File -FilePath $fileName -Encoding utf8
}

# Outputs confirmation that email signatures for all users were created.
Write-Output "Email signatures for all users have been successfully created."

The PowerShell script imports the Active Directory module to extract user data. It fetches the first name, last name, and title of all users from Active Directory and creates an HTML email signature for each user, containing the full name, user's position, and the company logo. These signatures are then saved as HTML files under a specified network path, with the filename matching the username.

Next, the file just needs to be copied to the correct location on the client. The following script can be used for this:

# Get the current user's username
$currentuser = $env:USERNAME

# Define the source path on the network share
# Replace "\\NetworkShare\Path\" with the actual network share path
$sourcePath = "" + $currentuser + ".htm"

# Define the destination path
$destinationPath = "C:\Users\" + $currentuser + "\AppData\Roaming\Microsoft\Signatures"

# Check if the source file exists
if (Test-Path $sourcePath) {
    # Copy the file
    Copy-Item -Path $sourcePath -Destination $destinationPath
    Write-Host "File was copied."
} else {
    Write-Host "The source file was not found."
}

This script can be used either as a logon script directly via Group Policy or integrated into existing software deployment solutions like Matrix42, Baramundi, etc.