New blog
Hi There, Just finished this blog and this will be my first post in my own little place on the internet. From now on i can document and contribute to …
Read ArticleOur IT Team still gets alot of calls with the question how to get their Outlook signature back when users receive a new device.
I know Microsoft is hard at work on this issue but do not have a solution currently.
My colleague gave me an interesting link from a blog from Jose Gabriel Ortega C. I really liked his idea of saving the signature in Onedrive. I decided to go a step further with proactive remediation and rewrite his solution in powershell.
My proactive remediation script consists of a detection and a remediation script.
First it gets the paths of all the locations the Outlook signature could be and does some checks.
The signature is saved in Outlook here:
#Windows directory
%APPDATA%\Roaming\Microsoft\Signatures
Or
The signature is backed up here in Onedrive and we need to set it back to Outlook. This is problably an existing employee that has gotten a new device.
#Onedrive directory
C:\Users\yourname\your-onedrive-folder\Signatures
We have 3 options in my detection script.
There is no Outlook signature present in Outlook %APPDATA% or in the signatures folder in Onedrive. This is probably a new employee that needs to setup its Outlook signature for the first time. We do nothing.
If there is a Outlook signature in Onedrive or Outlook %APPDATA% folder. We trigger the remediation script.
If there is a onedrive backup folder and a %APPDATA% folder. Your signature is synced between Onedrive and Outlook. Ofcourse we do not trigger the remediation script now.
The remediation script makes a Onedrive signatures map or a Outlook signature folder. Then it will create a junction between Outlook and your Outlook signature map. The junction makes sure if you update your Outlook folder, the changes will update in your Outlook signature folder too!
#Make folder junction
cmd /c mklink /J $LocalOutlookSignature $SignatureOnedrive
The only thing that needs to be done by the end-user is enable the “new messages” and “replies/forwards” in the picture below.
If someone knows how to automatically enable the new messages and Replies/forwards with a registry key? Please contact me!
Because we still need to get the user to do something in the end….
Make sure to test the script before you use this in production!
Use this link to get the whole proactive remediation script from my github page.
Or copy paste the code below:
#detection.ps1
#=============================================================================================================================
#
# Script Name: Outlook Signature
# Description: Set symlink between appdata\Microsoft\Signatures and onedrive\Signatures
# Written by: Vincent Verstraeten
#=============================================================================================================================
# Define Variables
$OneDrivePath = [Environment]::GetEnvironmentVariable("ONEDRIVE",[EnvironmentVariableTarget]::User)
$SignatureOnedrive = join-path -Path $OneDrivePath -ChildPath "Signatures"
$SignatureOutlook = Join-Path $env:APPDATA -ChildPath "Microsoft/Signatures"
try
{
if (!(test-path -Path "$SignatureOnedrive") -and !(test-path -Path "$SignatureOutlook") ) {
# Outlook Signature and Onedrive does not exist. Wait till Outlook signature is set in %APPDATA%.
exit 0
}
if (!(test-path -Path "$SignatureOnedrive") -or !(test-path -Path "$SignatureOutlook") ) {
# Outlook Signature or Microsoft signature does not exist in Onedrive, remediation needed.
exit 1
}
if (!(test-path -Path "$SignatureOutlook") -or ((Get-Item -Path $SignatureOutlook -Force).LinkType -ne "Junction") ) {
# Outlook Junction Signature does not exist in Appdata/Microsoft/Outlook, remediation needed
exit 1
}
else {
# Outlook Signature is synced, do not remediate.
exit 0
}
}
catch{
$errMsg = $_.Exception.Message
Write-Error $errMsg
exit 1
}
#=============================================================================================================================
# Script Name: Backup Outlook Signature to onedrive
# Description: Symlink Outlook Signature to onedrive New-Item -ItemType SymbolicLink -Path $LocalOutlookSignature -Target $SignatureOnedrive -Force
# Notes: Vincent Verstraeten 08/2022 New-Item -Path $SignatureOnedrive -ItemType "directory" -Force
#=============================================================================================================================
# Main script
# get local user folders
$env:APPDATA
$LocalOutlookSignature = Join-Path $env:APPDATA -ChildPath "Microsoft/Signatures"
$LocalOutlookBackupSignature = Join-Path $env:APPDATA -ChildPath "Microsoft/Signatures_backup"
$OneDrivePath = [Environment]::GetEnvironmentVariable("ONEDRIVE",[EnvironmentVariableTarget]::User)
$SignatureOnedrive = join-path -Path $OneDrivePath -ChildPath "Signatures"
if ((Test-Path -Path $LocalOutlookSignature -ErrorAction SilentlyContinue) -or ((Get-Item -Path $LocalOutlookSignature -Force -ErrorAction SilentlyContinue).LinkType -eq "Junction")) {
Copy-Item -Path $LocalOutlookSignature -Destination $LocalOutlookBackupSignature -recurse -Force
Remove-Item -LiteralPath $LocalOutlookSignature -Force -Recurse
if(!(Test-Path -Path $SignatureOnedrive)){
mkdir $SignatureOnedrive
# Make onedrive signatures map
}
cmd /c mklink /J $LocalOutlookSignature $SignatureOnedrive #Powershell command needs admin, only in preview windows(better use cmd here)
Copy-Item -Path "$LocalOutlookBackupSignature\*" -Destination $LocalOutlookSignature -recurse -Force
Remove-Item -LiteralPath $LocalOutlookBackupSignature -Force -Recurse
# Copy over local signature data to onedrive
}
#Check if onedrive signatures map is present but local microsoft signature outlook is not there. Then copy Onedrive Signature to outlook signature.
if (!(Test-Path $LocalOutlookSignature)) {
Copy-Item -Path $SignatureOnedrive -Destination $LocalOutlookBackupSignature -recurse -Force
cmd /c mklink /J $LocalOutlookSignature $SignatureOnedrive
Copy-Item -Path $LocalOutlookBackupSignature\* -Destination $SignatureOnedrive -recurse -Force
Remove-Item -LiteralPath $LocalOutlookBackupSignature -Force -Recurse
# Copy onedrive to outlook signature
}
if (!((Get-Item -Path $LocalOutlookSignature -Force).LinkType -eq "Junction")) {
Remove-Item -LiteralPath $LocalOutlookSignature -Force -Recurse
cmd /c mklink /J $LocalOutlookSignature $SignatureOnedrive
}