none
Script para firma de outlook RRS feed

  • Pregunta

  • Buenas estoy probando el siguiente script que encontré, para desplegar la firma de outlook a todos los clientes, pero después de realizar varias modificaciones no tengo forma de que cree correctamente los archivos .html .rtf y .txt, En principio crea los archivos pero la información que contiene es ilegible, aunque en el word si que inserta los valores del AD.

    Alguien puede ayudarme o pasar algún script que funcione.

    Gracias

    <#
        .SYNOPSIS
        Script to set Outlook 2010/2013 e-mail signature using Active Directory information
        .DESCRIPTION
        This script will set the Outlook 2010/2013 e-mail signature on the local client using Active Directory information.
        The template is created with a Word document, where images can be inserted and AD values can be provided.
        Author: Daniel Classon
        Version 2.0
        .DISCLAIMER
        All scripts and other powershell references are offered AS IS with no warranty.
        These script and functions are tested in my environment and it is recommended that you test these scripts in a test environment before using in your production environment.
        #>

    #Custom variables
    $SignatureName = 'template' #insert the company name (no spaces) - could be signature name if more than one sig needed
    $SigSource = "C:\temp\template.docx" #Path to the *.docx file, i.e "c:\temp\template.docx"
    $SignatureVersion = "2.0" #Change this if you have updated the signature. If you do not change it, the script will quit after checking for the version already on the machine
    $ForceSignature = '0' #Set to 1 if you don't want the users to be able to change signature in Outlook
     
    #Environment variables
    $AppData=(Get-Item env:appdata).value
    $SigPath = '\Microsoft\Signatures'
    $LocalSignaturePath = $AppData+$SigPath
    $RemoteSignaturePathFull = $SigSource
    #Copy version file
    If (-not(Test-Path -Path $LocalSignaturePath\$SignatureVersion))
    {
    New-Item -Path $LocalSignaturePath\$SignatureVersion -ItemType Directory
    }
    Elseif (Test-Path -Path $LocalSignaturePath\$SignatureVersion)
    {
    Write-Output "Latest signature already exists"
    break
    }
    #Check signature path (needs to be created if a signature has never been created for the profile
    if (-not(Test-Path -path $LocalSignaturePath)) {
     New-Item $LocalSignaturePath -Type Directory
    }
    #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()
    $ADDisplayName = $ADUser.DisplayName
    $ADEmailAddress = $ADUser.mail
    $ADTitle = $ADUser.title
    $ADDescription = $ADUser.description
    $ADTelePhoneNumber = $ADUser.TelephoneNumber
    $ADMobile = $ADUser.mobile
    $ADStreetAddress = $ADUser.streetaddress
    $ADCity = $ADUser.l
    $ADCustomAttribute1 = $ADUser.extensionAttribute1
    $ADModify = $ADUser.whenChanged
    #Copy signature templates from source to local Signature-folder
    Write-Output "Copying Signatures"
    Copy-Item "$Sigsource" $LocalSignaturePath -Recurse -Force
    $ReplaceAll = 2
    $FindContinue = 1
    $MatchCase = $False
    $MatchWholeWord = $True
    $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+'\'+$SignatureName+'.docx'
    $MSWord.Documents.Open($fullPath)
    $FindText = “DisplayName” 
    $ReplaceText = $ADDisplayName.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    ) 
    #Save new message signature
    Write-Output "Saving signatures"
    #Save HTML
    $path = $LocalSignaturePath+'\'+$SignatureName+".htm"
    $MSWord.ActiveDocument.saveas([ref]$path, [ref]$wdSaveFormat::wdFormatHTML);
    $MSWord.ActiveDocument.saveas($path, $wdSaveFormat::wdFormatHTML);
       
    #Save RTF
    $path = $LocalSignaturePath+'\'+$SignatureName+".rtf"
    $MSWord.ActiveDocument.SaveAs([ref]$path, [ref]$wdSaveFormat::wdFormatRTF);
    $MSWord.ActiveDocument.SaveAs($path, $wdSaveFormat::wdFormatRTF);
     
    #Save TXT   
    $path = $LocalSignaturePath+'\'+$SignatureName+".txt"
    $MSWord.ActiveDocument.SaveAs([ref]$path, [ref]$wdSaveFormat::wdFormatText);
    $MSWord.ActiveDocument.SaveAs($path, $wdSaveFormat::wdFormatRTF);
     
    $MSWord.ActiveDocument.Close();
    $MSWord.Quit();
     
    #Office 2010
    If (Test-Path HKCU:'\Software\Microsoft\Office\14.0')
    {
    If ($ForceSignature -eq '1')
        {
        Write-Output "Setting signature for Office 2010 as forced"
        New-ItemProperty HKCU:'\Software\Microsoft\Office\14.0\Common\MailSettings' -Name 'ReplySignature' -Value $SignatureName -PropertyType 'String' -Force
        New-ItemProperty HKCU:'\Software\Microsoft\Office\14.0\Common\MailSettings' -Name 'NewSignature' -Value $SignatureName -PropertyType 'String' -Force
        }
    else
    {
    Write-Output "Setting Office 2010 signature as available"
    $MSWord = New-Object -comobject word.application
    $EmailOptions = $MSWord.EmailOptions
    $EmailSignature = $EmailOptions.EmailSignature
    $EmailSignatureEntries = $EmailSignature.EmailSignatureEntries
    }
    }
    #Office 2013 signature
    If (Test-Path HKCU:Software\Microsoft\Office\15.0)
    {
    Write-Output "Setting signature for Office 2013"
    If ($ForceSignature -eq '0')
    {
    Write-Output "Setting Office 2013 as available"
    $MSWord = New-Object -ComObject word.application
    $EmailOptions = $MSWord.EmailOptions
    $EmailSignature = $EmailOptions.EmailSignature
    $EmailSignatureEntries = $EmailSignature.EmailSignatureEntries
    }
    If ($ForceSignature -eq '1')
    {
    Write-Output "Setting signature for Office 2013 as forced"
        If (Get-ItemProperty -Name 'NewSignature' -Path HKCU:'\Software\Microsoft\Office\15.0\Common\MailSettings') { }
        Else {
        New-ItemProperty HKCU:'\Software\Microsoft\Office\15.0\Common\MailSettings' -Name 'NewSignature' -Value $SignatureName -PropertyType 'String' -Force
        }
        If (Get-ItemProperty -Name 'ReplySignature' -Path HKCU:'\Software\Microsoft\Office\15.0\Common\MailSettings') { }
        Else {
        New-ItemProperty HKCU:'\Software\Microsoft\Office\15.0\Common\MailSettings' -Name 'ReplySignature' -Value $SignatureName -PropertyType 'String' -Force
        }
    }
    }

    lunes, 16 de enero de 2017 10:48

Todas las respuestas

  • Write-host "POR FAVOR ESPERE MIENTRAS SE CONFIGURA LA NUEVA FIRMA OUTLOOK, esto puede tardar un minuto.....:"
    $CompanyName = ’Company’
    $DomainName = ’Company.com’
     
    $SigSource = “\\$DomainName\NETLOGON\sig_files\$CompanyName”

    $ForceSignatureNew = "1"
    $ForceSignatureReplyForward = "1"
     
    $AppData=(Get-Item env:appdata).value
    $SigPath = “\Microsoft\Firmas“
    #$SigPath = “\Microsoft\Signatures“
    $LocalSignaturePath = $AppData+$SigPath
    $RemoteSignaturePathFull = $SigSource+“\“+$CompanyName+“.docx“

    $UserName = $env:username
    $Filter = “(&(objectCategory=User)(samAccountName=$UserName))”
    $Searcher = New-Object System.DirectoryServices.DirectorySearcher
    $Searcher.Filter = $Filter
    $ADUserPath = $Searcher.FindOne()
    $ADUser = $ADUserPath.GetDirectoryEntry()
    $ADDisplayName = $ADUser.DisplayName
    $ADEmailAddress = $ADUser.mail
    $ADTitle = $ADUser.title
    $ADTelePhoneNumber = $ADUser.TelephoneNumber
    $ADFaxNumber = $ADUser.facsimiletelephonenumber
    $ADstreetAddress = $ADUser.streetAddress

    Write-host "Nombre: $ADDisplayName"
    Write-host "Cargo: $ADTitle"
    Write-host "Interno: $ADTelePhoneNumber"
    Write-host "Fax: $ADFaxNumber"
    Write-host "Direccion: $ADstreetAddress"

    Write-host "Creando Registros en RegEdit............"
    $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

    $MSWord = New-Object -com word.application
    $EmailOptions = $MSWord.EmailOptions
    $EmailSignature = $EmailOptions.EmailSignature
    $EmailSignatureEntries = $EmailSignature.EmailSignatureEntries
    $EmailSignature.ReplyMessageSignature=$CompanyName #Para que la firma se coloque en Reenviar
    $EmailSignature.NewMessageSignature=$CompanyName #Para que la firma se coloque en Nuevo
    $MSWord.Quit()



    Write-host "Realizando copia de la firma Original......"
    if ($SignatureVersion -eq $SigVersion){}
    else
    {
    Copy-Item “$SignatureSourceFiles\*” $LocalSignaturePath -Recurse -Force

    $ReplaceAll = 2
    $FindContinue = 1
    $MatchCase = $False
    $MatchWholeWord = $True
    $MatchWildcards = $False
    $MatchSoundsLike = $False
    $MatchAllWordForms = $False
    $Forward = $True
    $Wrap = $FindContinue
    $Format = $False

    Write-host "Colocando el Nombre a la firma......"

    $MSWordtxt = New-Object -comObject Word.Application
    $fullPath = $LocalSignaturePath+’\'+$CompanyName+’.txt’
    #Write-host "Nombre: $fullPath"

    $doctxt = $MSWordtxt.Documents.Open($fullPath)

    $FindText = “DisplayName”
    $ReplaceText = $ADDisplayName.ToString()
    $MSWordtxt.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )

    $FindText = “Title”
    $ReplaceText = $ADTitle.ToString()
    $MSWordtxt.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )

    $FindText = "TelePhoneNumber"
    $ReplaceText = $ADTelePhoneNumber.ToString()
    $MSWordtxt.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )

    $FindText = "FaxNumber"
    $ReplaceText = $ADFaxNumber.ToString()
    $MSWordtxt.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )

    $FindText = "Address"
    $ReplaceText = $ADstreetAddress.ToString()
    $MSWordtxt.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )

    $FindText = "email1"
    $ReplaceText = $ADEmailAddress.ToString()
    $MSWordtxt.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )

    $MSWordtxt.ActiveDocument.Close()  
    $MSWordtxt.Quit()

    $MSWord = New-Object -comObject Word.Application
    $fullPath = $LocalSignaturePath+’\'+$CompanyName+’.htm’
    #Write-host "Nombre: $fullPath"

    $doc = $MSWord.Documents.Open($fullPath)

    $FindText = “DisplayName”
    $ReplaceText = $ADDisplayName.ToString()
    $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )

    Write-host "Colocando el Cargo a la firma......"
    $FindText = “Title”
    $ReplaceText = $ADTitle.ToString()
    $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )

    Write-host "Colocando el Interno a la firma......"
    $FindText = "TelePhoneNumber"
    $ReplaceText = $ADTelePhoneNumber.ToString()
    $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )

    Write-host "Colocando el Fax a la firma......"
    $FindText = "FaxNumber"
    $ReplaceText = $ADFaxNumber.ToString()
    $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )

    Write-host "Colocando la dirección a la firma......"
    $FindText = "Address"
    $ReplaceText = $ADstreetAddress.ToString()
    $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )

    Write-host "Colocando el email a la firma......"
    $FindText = "email1"
    $ReplaceText = $ADEmailAddress.ToString()
    $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )


    $MSWord.ActiveDocument.Close()  
    $MSWord.Quit()

    Write-host "fin de la creación de la Firma Outlook"
    Write-host "Puede cerrar la ventan si esta no lo hace por si misma"

     
    }
    jueves, 7 de diciembre de 2017 13:07