+ Post New Thread
Results 1 to 7 of 7
Scripts Thread, Powershell script adding Signature for Outlook / Exchange in Coding and Web Development; I use this script modiefied by thescareface to set Outlook signature for all our users, but I want the Reply/forward ...
  1. #1

    Join Date
    May 2013
    Posts
    5
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Powershell script adding Signature for Outlook / Exchange

    I use this script modiefied by thescareface to set Outlook signature for all our users, but I want the Reply/forward signature to be something else then the standard signature..

    In reply/forward I want the signature to only have:

    Best Reagards
    FullName LastName
    Title
    Company name

    While all new mails should have:
    Best Regards
    FullName LastName
    Title
    Company address
    P.o.box
    etc
    etc

    How can I modify the script to handle this feature?

    Code:
    ###########################################################################"
    #
    #        Our script
    #
    ###########################################################################"
    #Custom variables
    $CompanyName = 'ourcompany'
    $DomainName = 'our.domain.local'
    $SigSource = "\\our.domain.local\sig_files\$CompanyName"
    $ForceSignatureNew = '1' #When the signature are forced the signature are enforced as default signature for new messages the next time the script runs. 0 = no force, 1 = force
    $ForceSignatureReplyForward = '0' #When the signature are forced the signature are enforced as default signature for reply/forward messages the next time the script runs. 0 = no force, 1 = force
    #Environment variables
    $AppData=(Get-Item env:appdata).value
    $SigPath = '\Microsoft\Signatures'
    $LocalSignaturePath = $AppData+$SigPath
    $RemoteSignaturePathFull = $SigSource+'\'+$CompanyName+'.docx'
    #Get Active Directory information for current user
    $UserName = $env:username
    $Filter = "(&(objectCategory=User)(samAccountName=$UserName))"
    $Searcher = New-Object System.DirectoryServices.DirectorySearcher
    $Searcher.Filter = $Filter
    $ADUserPath = $Searcher.FindOne()
    $ADUser = $ADUserPath.GetDirectoryEntry()
    $ADFirstName = $ADUser.FirstName
    $ADLastName = $ADUser.LastName
    $ADTitle = $ADUser.title
    $ADhomephone = $ADUser.homephone
    $ADmobile = $ADUser.mobile
    #Setting registry information for the current user
    $CompanyRegPath = "HKCU:\Software\"+$CompanyName
    if (Test-Path $CompanyRegPath)
    {}
    else
    {New-Item -path "HKCU:\Software" -name $CompanyName}
    if (Test-Path $CompanyRegPath'\Outlook Signature Settings')
    {}
    else
    {New-Item -path $CompanyRegPath -name "Outlook Signature Settings"}
    $SigVersion = (gci $RemoteSignaturePathFull).LastWriteTime  #When was the last time the signature was written
    $ForcedSignatureNew = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').ForcedSignatureNew
    $ForcedSignatureReplyForward = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').ForcedSignatureReplyForward
    $SignatureVersion = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').SignatureVersion
    Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name SignatureSourceFiles -Value $SigSource
    $SignatureSourceFiles = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').SignatureSourceFiles
    #Forcing signature for new messages if enabled
    if ($ForcedSignatureNew -eq '1')
    {
    #Set company signature as default for New messages
    $MSWord = New-Object -com word.application
    $EmailOptions = $MSWord.EmailOptions
    $EmailSignature = $EmailOptions.EmailSignature
    $EmailSignatureEntries = $EmailSignature.EmailSignatureEntries
    $EmailSignature.NewMessageSignature=$CompanyName
    $MSWord.Quit()
    }
    #Forcing signature for reply/forward messages if enabled
    if ($ForcedSignatureReplyForward -eq '1')
    {
    #Set company signature as default for Reply/Forward messages
    $MSWord = New-Object -com word.application
    $EmailOptions = $MSWord.EmailOptions
    $EmailSignature = $EmailOptions.EmailSignature
    $EmailSignatureEntries = $EmailSignature.EmailSignatureEntries
    $EmailSignature.ReplyMessageSignature=$CompanyName
    $MSWord.Quit()
    }
    #Copying signature sourcefiles and creating signature if signature-version are different from local version
    if ($SignatureVersion -eq $SigVersion){}
    else
    {
        #Copy signature templates from domain to local Signature-folder
        Copy-Item "$SignatureSourceFiles\*" $LocalSignaturePath -Recurse -Force
        $ReplaceAll = 2
        $FindContinue = 1
        $MatchCase = $True
        $MatchWholeWord = $Talse
        $MatchWildcards = $False
        $MatchSoundsLike = $False
        $MatchAllWordForms = $False
        $Forward = $True
        $Wrap = $FindContinue
        $Format = $False
        #Insert variables from Active Directory to rtf signature-file
        $MSWord = New-Object -com word.application
        $fullPath = $LocalSignaturePath+'\'+$CompanyName+'.docx'
        $MSWord.Documents.Open($fullPath)
        $FindText = "FirstName"
        $ReplaceText = $ADFirstName.ToString()
        $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )
        $FindText = "LastName"
        $ReplaceText = $ADLastName.ToString()
        $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )
        $FindText = "Title"
        $ReplaceText = $ADTitle.ToString()
        $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )
        $FindText = "homephone"
        $ReplaceText = $ADhomephone.ToString()
        $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )
        $FindText = "svgmobile"
        $ReplaceText = $ADmobile.ToString()
        $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )
        $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatHTML");
        $path = $LocalSignaturePath+'\'+$CompanyName+".htm"
        $MSWord.ActiveDocument.saveas([ref]$path, [ref]$saveFormat)
        $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatRTF");
        $path = $LocalSignaturePath+'\'+$CompanyName+".rtf"
        $MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$saveFormat)
        $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatText");
        $path = $LocalSignaturePath+'\'+$CompanyName+".txt"
        $MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$SaveFormat)
        $MSWord.ActiveDocument.Close()
        $MSWord.Quit()
    }
    #Stamp registry-values for Outlook Signature Settings if they doesn`t match the initial script variables. Note that these will apply after the second script run when changes are made in the "Custom variables"-section.
    if ($ForcedSignatureNew -eq $ForceSignatureNew){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ForcedSignatureNew -Value $ForceSignatureNew}
    if ($ForcedSignatureReplyForward -eq $ForceSignatureReplyForward){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ForcedSignatureReplyForward -Value $ForceSignatureReplyForward}
    if ($SignatureVersion -eq $SigVersion){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name SignatureVersion -Value $SigVersion}

  2. #2

    Join Date
    May 2013
    Posts
    5
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Anyone? I just want to add defaut signature for reply emails(FirstName/LastName). I already got the one for new emails working fine.

  3. #3
    TheScarfedOne's Avatar
    Join Date
    Apr 2007
    Location
    Plymouth, Devon
    Posts
    1,166
    Thank Post
    562
    Thanked 153 Times in 139 Posts
    Blog Entries
    78
    Rep Power
    80
    Only just seen this...will go back and reverse engineer it as not modded that script in ages!!

  4. #4

    Join Date
    Jan 2014
    Location
    Invercargill
    Posts
    3
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Did you got this working? I have a similar requirement. See the attached ps1
    Attached Files Attached Files
    Last edited by bijuma; 3rd February 2014 at 12:32 AM. Reason: Added script attachment

  5. #5

    Join Date
    Jan 2014
    Location
    Invercargill
    Posts
    3
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Different signatures for New mail and replies forwards

    Done .. use the script to generate separate signatures for new and replies/forward.
    Attached Files Attached Files

  6. #6

    Join Date
    Jan 2014
    Location
    Invercargill
    Posts
    3
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    See the latest file attached.SignReplynew.ps1

  7. #7

    Join Date
    Aug 2013
    Location
    SC
    Posts
    1
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Good to have for later.

    Thanks!

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 2
    Last Post: 24th February 2011, 01:01 PM
  2. Replies: 4
    Last Post: 10th May 2010, 12:05 PM
  3. Replies: 8
    Last Post: 12th February 2009, 03:54 PM
  4. Replies: 0
    Last Post: 24th January 2008, 02:58 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •