Writing about what I'm learning

Creating a startup script that applies an Outlook signature

Last week I worked on a startup script that created an html file. I looked at the following websites:

https://office365itpros.com/2020/02/19/updating-outlook-signature-powershell/

https://lazyadmin.nl/office-365/outlook-html-signature/

First, I create a new GPO, and apply it only to my “Employees” OU. I apply this GPO using the User Configuration > Windows Settings > Scripts > Logon policy.

I wrote a script that deletes the .html file that is used for the Outlook signature every time on startup if a user ever alters the file.

First, I define variables for the registry path that I’ll use to force the change, and prevent changing the signature in Outlook. I also take from Active Directory certain values from a user account’s attributes that will be put in the signature, including an employee’s department, first and last name, and their their telephone number.

$OutlookProfilePath = "HKCU:\Software\Microsoft\Office\16.0\Common\MailSettings"
$userProfile = $env:userprofile
$HtmlPath = "$userProfile\AppData\Roaming\Microsoft\Signatures\test.htm"
$SignatureName = "test"

I then create an HTML file where Outlook stores its signature in C:\Users\(user profile)\AppData\Roaming\Microsoft\Signatures and append line by line the HTML code I desire. The code I found in office365itpros.com kept throwing syntax errors and I thought this would be the easiest way around it.

"<!DOCTYPE html>"  |Out-File -FilePath $HtmlPath -Append
    "<html>"  |Out-File -FilePath $HtmlPath -Append
    "<head>"  |Out-File -FilePath $HtmlPath -Append
    "<title>Microsoft Office Outlook Signature</title>"  |Out-File -FilePath $HtmlPath -Append

    "<style>"  |Out-File -FilePath $HtmlPath -Append
    "body {font-family:Calibri; font-size:11pt;color:#8fe0ff;}"  |Out-File -FilePath $HtmlPath -Append
    "img {border:0px; padding:0px 0px 0px 0px; margin: 0px 0px 0px 0px; vertical-align:middle;}"  |Out-File -FilePath $HtmlPath -Append
    "</style>"  |Out-File -FilePath $HtmlPath -Append

    "</head>"  |Out-File -FilePath $HtmlPath -Append
    "<body>"  |Out-File -FilePath $HtmlPath -Append

    "<div align=left><p>"  |Out-File -FilePath $HtmlPath -Append
    "<font color=#75b4e3><strong>$userName</strong></font>"  |Out-File -FilePath $HtmlPath -Append
    "<br />"  |Out-File -FilePath $HtmlPath -Append
    "$userDepartment"  |Out-File -FilePath $HtmlPath -Append
    "</p></div>"  |Out-File -FilePath $HtmlPath -Append

    "<div align=left><p>"  |Out-File -FilePath $HtmlPath -Append
    "<font color=#75b4e3><strong>E: </strong></font>"  |Out-File -FilePath $HtmlPath -Append
    "<a href= mailto:lhwang4@wgu.edu>lhwang4@wgu.edu</a>"  |Out-File -FilePath $HtmlPath -Append
    "<br />"  |Out-File -FilePath $HtmlPath -Append

    "<font color=#75b4e3><strong>Ext: </strong></font>$userTelephoneNumber"  |Out-File -FilePath $HtmlPath -Append

    "<br/>"  |Out-File -FilePath $HtmlPath -Append

    "<font color=#75b4e3><strong>W: </strong></font>"  |Out-File -FilePath $HtmlPath -Append
    "<a href='http://www.weather.com'>www.weather.com</a>"  |Out-File -FilePath $HtmlPath -Append
    "&nbsp;&nbsp;"  |Out-File -FilePath $HtmlPath -Append
    "<img src='https://upload.wikimedia.org/wikipedia/commons/7/77/The_Weather_Channel_logo_2005-present.svg' align=bottom width=14 height=14 />"  |Out-File -FilePath $HtmlPath -Append
    "&nbsp;"  |Out-File -FilePath $HtmlPath -Append
    "</p></div>"  |Out-File -FilePath $HtmlPath -Append

    "<div align=left><p>"  |Out-File -FilePath $HtmlPath -Append
    "<img src='https://upload.wikimedia.org/wikipedia/commons/7/77/The_Weather_Channel_logo_2005-present.svg' width=103 height=103 />"  |Out-File -FilePath $HtmlPath -Append
    "</p></div>"  |Out-File -FilePath $HtmlPath -Append

    "<font color=#75b4e3><strong>Weather signature</strong></font>"  |Out-File -FilePath $HtmlPath -Append
    "<br /><br />"  |Out-File -FilePath $HtmlPath -Append

    "</body></html"  |Out-File -FilePath $HtmlPath -Append
    

I then create the registry settings, “NewSignature” and “ReplySignature,” creating new string values that use the value of the name of the signature, which is “test”

Get-Item -Path $OutlookProfilePath | New-Itemproperty -Name "NewSignature" -value $SignatureName -Propertytype string -Force 
    Get-Item -Path $OutlookProfilePath | New-Itemproperty -Name "ReplySignature" -value $SignatureName -Propertytype string -Force

On restart you can see the change in signature. Note that as others have mentioned, though this works for the desktop app version of Outlook, this won’t work for applying the signature via the iOS/Android versions of Outlook

Leave a comment

Design a site like this with WordPress.com
Get started