Outlook signature generator script

Generates Outlook signatures and can embed user details from Active Directory such as an email address or phone number. Any relevant AD attribute can be embedded. Will process all templates in a defined folder and supports default new/reply settings and deleting signatures.

 
 
 
 
 
4 Star
(1)
1,365 times
Add to favorites
Office
10/12/2020
E-mail Twitter del.icio.us Digg Facebook
  • Error COM Component
    1 Posts | Last post February 14, 2020
    • Hello in a Windows 10 with the last Outlook 2016 O365 when try to run the script show an error but, create only the New signature ignore the Reply:
      
      Devuelto error HRESULT E_FAIL de una llamada a un componente COM.
      En \\domain.dom\NETLOGON\Signatures\Movil\OutlookSignatureScript.ps1: 299 Carácter: 21
      + ...             $Word.EmailOptions.EmailSignature.NewMessageSignature = $ ...
      +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      2 template(s) found at: \\amcargo.dom\NETLOGON\Signatures\Movil
      Outlook profile status: Default profile found.
      Template, Action, Invalid Tags, Status 
      NuevoCorreo-new.docx, new, 0, Error: Devuelto error HRESULT E_FAIL de una llamada a un componente COM.
  • How to set template as default
    2 Posts | Last post February 04, 2020
    • Hello,
      I cannot set template as default or reply as shown below. Could anyone help?
      PS C:\\OutlookSignatureScript_v1.1> .\OutlookSignatureScript.ps1 .\Long_Sig-new.docx
      
      2 template(s) found at: \\ServerName\OutlookSignatureScript_v1.1
      Outlook profile status: Default profile found.
      
      Template, Action, Invalid Tags, Status
      Long_Sig.docx, None, 0, Skipped
      Short_Sig.docx, None, 0, Skipped 
    • Hi,
      
      The log details you posted show Action as "None", meaning that the script couldn't match the section after the dash (-) in the template file name. Make sure template files are named correctly with the action.
      
      Chris
  • Error when run the scipt
    2 Posts | Last post February 04, 2020
    • I was runnig your script without problems in many PC's but some of day get this error:
      
      Could not load file or assembly 'Microsoft.Office.Interop.Word, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies.
      Microsoft.Office.Interop.Word.dll 
      
      I dont find why happen this or how to solve it.
      
    • Hi Nick,
      
      "Microsoft.Office.Interop.Word, Version=12.0.0.0" is likely from Office 2007 which isn't supported. I would see if you can upgrade those installs to Office 2010 or newer.
      
      Chris
  • Windows 7 - Error
    3 Posts | Last post November 20, 2019
    • Hello,the script work perfect on Windows 10 with the change done by MarkoKuky but when run on Windows 7 get error, is like try to edit the word on the shared folder (the users has only rights for read and execute)
    • Hi
      
      I just added an if statement to fix the windows 7 issue. (See below)
      
      If ($os -like "*windows 7*")
      {
                  # save the signature template files in html/rtf/txt formats
                  $SavePath = Join-Path -Path $OutlookSignaturePath -ChildPath "$TemplateName.htm"
                  $Word.ActiveDocument.SaveAs([Ref]$SavePath, [Ref][Microsoft.Office.Interop.Word.WdSaveFormat]::wdFormatHTML)
      
                  $SavePath = Join-Path -Path $OutlookSignaturePath -ChildPath "$TemplateName.rtf"
                  $Word.ActiveDocument.SaveAs([Ref]$SavePath, [Ref][Microsoft.Office.Interop.Word.WdSaveFormat]::wdFormatRTF)
      
                  $SavePath = Join-Path -Path $OutlookSignaturePath -ChildPath "$TemplateName.txt"
                  $Word.ActiveDocument.SaveAs([Ref]$SavePath, [Ref][Microsoft.Office.Interop.Word.WdSaveFormat]::wdFormatText)
                  $Word.ActiveDocument.Close()
      
      } 
      
      Else {
      
                  # save the signature template files in html/rtf/txt formats
                  [string]$SavePath = Join-Path -Path $OutlookSignaturePath -ChildPath "$TemplateName.htm"
                  $Word.ActiveDocument.SaveAs([Ref]$SavePath, 8)
      
                  [string]$SavePath = Join-Path -Path $OutlookSignaturePath -ChildPath "$TemplateName.rtf"
                  $Word.ActiveDocument.SaveAs([Ref]$SavePath, 6)
      
                  [string]$SavePath = Join-Path -Path $OutlookSignaturePath -ChildPath "$TemplateName.txt"
                  $Word.ActiveDocument.SaveAs([Ref]$SavePath, 2)
                  $Word.ActiveDocument.Close()
      }
      
    • Thanks for the code Dennis. I updated with something similar that should cover the issues with certain Windows/Office/Powershell versions treating that SaveAs method differently.
  • Error and Doesn't set New Reply When Outlook 365 Open
    2 Posts | Last post November 20, 2019
    • Chris
      
      The script is almost 100% functional for me.  But I get the error below everytime I run it from PS with Outlook 365 closed.
      
      Write-EventLog : The source name "OutlookSignature" does not exist on computer "localhost".
      At C:\Users\user\Desktop\MySignature\OutlookSignature\OutlookSignatureScript.ps1:37 char:13
      
      If Outlook is open it does not set the signature for "New" emails.  It does set it for New emails if Outlook 365 is closed.
      
      Additional Error When Outlook 365 Open
      Specified cast is not valid.
      At C:\Users\user\Desktop\MySignature\OutlookSignature\OutlookSignatureScript.ps1:272 char:21
      + ...             $Word.EmailOptions.EmailSignature.NewMessageSignature = $ ...
      
      Thanks
    • Hi areile,
      
      The first error is expected, unless a event log source named "OutlookSignature" is created using an admin account.
      
      The second issue I'm not able to recreate, I can't easily test with an Office 365 version unfortunately.
  • Detect signature path automatically
    2 Posts | Last post November 20, 2019
    • Thanks for sharing! It is a great script and works flawlessly with suggested changes from MarkoKuky.
      
      It would be nice if the script could detect the installed language automatically and set the signature path accordingly.
      I have Office with Swedish language installed in my domain and for some reason some signature paths are in English and some in Swedish.
      
      I suppose Office 2019 signature path is in English regardless of interface language which is Swedish in my case.
      
      Signature path in English:
      %appdata%\Microsoft\Signatures
      
      Signature path in Swedish:
      %appdata%\Microsoft\Signaturer
      
    • I added an update to get the signature folder name from the registry, this should get the localised name. Unless there are multiple Outlook versions using different languages installed on the same machine maybe.
  • Cannot create *.html file
    1 Posts | Last post December 04, 2018
    • Hi Chris,
      
      Thanks for sharing. Do you have any idea why I get an error on line #254:
      
      ------------------------------------------
      
      1 template(s) found at: C:\Users\[.........]\Downloads\OutlookSignatureScript\
      Outlook profile status: Default profile found.
      
      Template, Action, Invalid Tags, Status 
      Long_Sig.docx, None, 0, Error: Exception setting "SaveAs": Cannot convert the "C:\Users\[.........]\AppData\Roaming\Microsoft\Signatures\Long_Sig.htm" value of type "psobject
      " to type "Object".
      
      
      Exception setting "SaveAs": Cannot convert the "C:\Users\[.........]\AppData\Roaming\Microsoft\Signatures\Long_Sig.htm" value of type "psobject" to type "Object".
      At C:\Users\[.........]\OutlookSignatureScript\OutlookSignatureScript.ps1:254 char:13
      +             $Word.ActiveDocument.SaveAs([Ref]$SavePath, [Ref][Microso ...
      +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
          + FullyQualifiedErrorId : RuntimeException
      
  • Exception from HRESULT: 0x80020005 Error
    4 Posts | Last post November 16, 2018
    • Hi Chris,
      Thanks for this script, I'm trying to use this but after I finish all needed setting I'm still getting this error:
      WARNING: The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security.
      Exception calling "SaveAs" with "2" argument(s): "Type mismatch. (Exception from HRESULT: 0x80020005
      (DISP_E_TYPEMISMATCH))"
      At C:\Outlook_Signature.ps1:254 char:13
      +             $Word.ActiveDocument.SaveAs([Ref]$SavePath, [Ref][Microsoft.Office.I ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
          + FullyQualifiedErrorId : COMException
      Can you help me with this?
      Thanks
      Anis
    • Hi Anis,
      
      If you paste the following into Powershell does it return true or false?
      
      Test-Path -Path ($env:APPDATA+'\Microsoft\Signatures')
      
      
      From the config at the top of the script:
      
      # Path Outlook loads signature files from, default is for English localisations.
      $OutlookSignaturePath = $env:APPDATA+'\Microsoft\Signatures'
      
      If the machine running the script is not using English you will need to check this path.
      
      Thanks
    • I solved it by doing this(lines 252-261):
      
       # save the signature template files in html/rtf/txt formats
                  [string]$SavePath = Join-Path -Path $OutlookSignaturePath -ChildPath "$TemplateName.htm"
                  $Word.ActiveDocument.SaveAs([Ref]$SavePath, 8)
      
                  [string]$SavePath = Join-Path -Path $OutlookSignaturePath -ChildPath "$TemplateName.rtf"
                  $Word.ActiveDocument.SaveAs([Ref]$SavePath, 6)
      
                  [string]$SavePath = Join-Path -Path $OutlookSignaturePath -ChildPath "$TemplateName.txt"
                  $Word.ActiveDocument.SaveAs([Ref]$SavePath, 2)
                  $Word.ActiveDocument.Close()
    • Hi Marko,
      
      Thanks for the details of what fixed it for you. What version of Office/Word are you running this with? Did you make any other changes? I can't recreate the original issue at the moment.