Hello, I found this awesome script online to create an email signature in a users local Outlook. It is all working via a GPO, however, if I wanted to make any changes to the html or the script on the server to change the .htm being created, I would have to go into each user’s appdata folders and delete the file so it would be recreated the next time they logon. Can someone help with what I need to add to this script for it to overwrite/replace the current file in the appdata/user/roaming/MSFT/signatures folder folder every time script is run?
# Gets the path to the user appdata folder
$AppData = (Get-Item env:appdata).value
# This is the default signature folder for Outlook
$localSignatureFolder = $AppData+'\Microsoft\Signatures'
# This is a shared folder on your network where the signature template should be
$templateFilePath = "C:\Users\\Desktop\template.html"
# Get the current logged in username
$userName = $env:username
# The following 5 lines will query AD and get an ADUser object with all information
$filter = "(&(objectCategory=User)(samAccountName=$userName))"
$searcher = New-Object System.DirectoryServices.DirectorySearcher
$searcher.Filter = $filter
$ADUserPath = $searcher.FindOne()
$ADUser = $ADUserPath.GetDirectoryEntry()
# Now extract all the necessary information for the signature
$name = $ADUser.displayName
$email = $ADUser.mail
$job = $ADUser.description
$department = $ADUser.department
$phone = $ADUser.telephonenumber
$address = $ADUser.streetaddress
$website = $ADUser.wWWHomePage
$city = $ADUser.l
$mobile = $ADUser.mobile
$state = $ADUser.st
$postcode = $ADUser.postalCode
$namePlaceHolder = "DISPLAY_NAME"
$emailPlaceHolder = "EMAIL"
$jobPlaceHolder = "JOB_TITLE"
$departmentPlaceHolder = "DEPARTMENT"
$phonePlaceHolder = "PHONE"
$addressPlaceHolder = "ADDRESS"
$websitePlaceHolder = "WEBSITE"
$cityPlaceholder = "SUBURB"
$mobilePlaceholder = "MOBILE"
$statePlaceHolder = "STATE"
$postcodePlaceHolder = "POSTCODE"
$rawTemplate = get-content $templateFilePath"\template.html"
$signature = $rawTemplate -replace $namePlaceHolder,$name
$rawTemplate = $signature
$signature = $rawTemplate -replace $emailPlaceHolder,$email
$rawTemplate = $signature
$signature = $rawTemplate -replace $phonePlaceHolder,$phone
$rawTemplate = $signature
$signature = $rawTemplate -replace $jobPlaceHolder,$job
$rawTemplate = $signature
$signature = $rawTemplate -replace $departmentPlaceHolder,$department
$rawTemplate = $signature
$signature = $rawTemplate -replace $websitePlaceHolder,$website
$rawTemplate = $signature
$signature = $rawTemplate -replace $cityPlaceHolder,$city
$rawTemplate = $signature
$signature = $rawTemplate -replace $mobilePlaceHolder,$mobile
$rawTemplate = $signature
$signature = $rawTemplate -replace $statePlaceHolder,$state
$rawTemplate = $signature
$signature = $rawTemplate -replace $postcodePlaceHolder,$postcode
$rawTemplate = $signature
$signature = $rawTemplate -replace $addressPlaceHolder,$address
# Save it as <username>.htm
$fileName = $localSignatureFolder + "\" + $userName + ".htm"
# Gets the last update time of the template.
if(test-path $templateFilePath){
$templateLastModifiedDate = [datetime](Get-ItemProperty -Path $templateFilePath -Name LastWriteTime).lastwritetime
}
# Checks if there is a signature and its last update time
if(test-path $filename){
$signatureLastModifiedDate = [datetime](Get-ItemProperty -Path $filename -Name LastWriteTime).lastwritetime
if((get-date $templateLastModifiedDate) -gt (get-date $signatureLastModifiedDate)){
$signature > $fileName
}
}else{
$signature > $fileName
}