none
Корпоративная подпись в Outlook через PS RRS feed

  • Вопрос

  • Здравствуйте !

    Есть шаблон:

    \\domain.ru\NETLOGON\Signatures\CorpSignature.docx

    Есть скрипт:

    #Custom variables 
    $CompanyName = ‘CorpSignature’ 
    $DomainName = ‘domain.ru’ 
     
    $SigSource = “\\domain.ru\NETLOGON\Signatures” 
    $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 = "1" #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 = "\\domain.ru\NETLOGON\Signatures\CorpSignature.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() 
    $ADDisplayName = $ADUser.DisplayName 
    $ADEmailAddress = $ADUser.mail 
    $ADTitle = $ADUser.title 
    $ADTelePhoneNumber = $ADUser.TelephoneNumber 
     
    #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 = $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+’\'+$CompanyName+’.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    ) 
     
    $MSWord.Selection.Find.Execute(“Email”) 
     
    $MSWord.ActiveDocument.Hyperlinks.Add($MSWord.Selection.Range, “mailto:”+$ADEmailAddress.ToString(), $missing, $missing, $ADEmailAddress.ToString()) 
     
    $MSWord.ActiveDocument.Save() 
    $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], “wdFormatHTML”); 
    [ref]$BrowserLevel = “microsoft.office.interop.word.WdBrowserLevel” -as [type] 
     
    $MSWord.ActiveDocument.WebOptions.OrganizeInFolder = $true 
    $MSWord.ActiveDocument.WebOptions.UseLongFileNames = $true 
    $MSWord.ActiveDocument.WebOptions.BrowserLevel = $BrowserLevel::wdBrowserLevelMicrosoftInternetExplorer6 
    $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+”.rtf” 
    $MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$saveFormat) 
     
    $path = $LocalSignaturePath+’\'+$CompanyName+”.txt” 
    $MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$SaveFormat::wdFormatText) 
    $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}

    Помогите переделать под шаблон чтобы при входе пользователя в систему срабатывал срипт и подставлял нужные поля из ад

    Заранее благодарен !

    15 апреля 2016 г. 10:45

Ответы

  • Получилось если кому интересно вот рабочий вариант:

    #Custom variables
    $CompanyName = ‘DOMAIN'
    $SigSource = "\\domain.ru\NETLOGON\Signatures"
    $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 = '1' #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
    $LocalSignatureFile = $LocalSignaturePath+'\'+$CompanyName+' официальная.files'
    $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()
    $ADDisplayName = $ADUser.DisplayName
    $ADEmailAddress = $ADUser.mail
    $ADTitle = $ADUser.title
    $ADTelePhoneNumber = $ADUser.TelephoneNumber
    $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
    #присваиваем переменные взяв значения из реестра
    $TelephoneNumberREG = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').TelephoneNumber
    $DisplayNameREG = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').DisplayName
    $EmailAddressREG = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').EmailAddress
    $ADTitleREG = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').ADTitle
    
    $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
    $FileExists =  Test-Path "$LocalSignatureFile"
    if ($SignatureVersion -eq $SigVersion -And $TelephoneNumberREG -eq $ADTelePhoneNumber -And $mobileREG -eq $ADmobile -And $DisplayNameREG -eq $ADDisplayName -And $EmailAddressREG -eq $ADEmailAddress -And $ADTitleREG -eq $ADTitle -and $FileExists -eq $true) {}
    else
    {
    #Copy signature templates from domain to local Signature-folder
    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
    
    #Insert variables from Active Directory to rtf signature-file
    $MSWord = New-Object -com word.application
    $fullPath = $LocalSignaturePath+'\'+$CompanyName+'.docx'
    $MSWord.Documents.Open($fullPath)
    
    $FindText = "TelephoneNumber"
    $ReplaceText = $ADTelephoneNumber.ToString()
    $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )
    
    $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    )
    
    $FindText = "mobile"
    $ReplaceText = $ADmobile.ToString()
    $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )
    
    $MSWord.Selection.Find.Execute("Email")
    
    $MSWord.ActiveDocument.Hyperlinks.Add($MSWord.Selection.Range, "mailto:"+$ADEmailAddress.ToString(), $missing, $missing, $ADEmailAddress.ToString())
    
    $MSWord.ActiveDocument.Save()
    $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatHTML");
    [ref]$BrowserLevel = "microsoft.office.interop.word.WdBrowserLevel" -as [type]
    
    $MSWord.ActiveDocument.WebOptions.OrganizeInFolder = $true
    $MSWord.ActiveDocument.WebOptions.UseLongFileNames = $true
    $MSWord.ActiveDocument.WebOptions.BrowserLevel = $BrowserLevel::wdBrowserLevelMicrosoftInternetExplorer6
    $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+" официальная.rtf"
    $MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$saveFormat)
    
    $path = $LocalSignaturePath+'\'+$CompanyName+" официальная.txt"
    $MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$SaveFormat)    #::wdFormatText)
    $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}
    
    #проверить актуальность тел. номера
    if ($TelephoneNumberREG -eq $ADTelePhoneNumber){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name TelephoneNumber -Value $ADTelePhoneNumber}
    if ($TelephoneNumberREG -eq $ADTelePhoneNumber){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name TelephoneNumber -Value $ADTelePhoneNumber}
    
    #проверить актуальность ФИО
    if ($DisplayNameREG -eq $ADDisplayName){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name DisplayName -Value $ADDisplayName}
    if ($DisplayNameREG -eq $ADDisplayName){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name DisplayName -Value $ADDisplayName}
    
    #проверить актуальность e-mail
    if ($EmailAddressREG -eq $ADEmailAddress){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name EmailAddress -Value $ADEmailAddress}
    if ($EmailAddressREG -eq $ADEmailAddress){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name EmailAddress -Value $ADEmailAddress}
    
    #проверить актуальность должности
    if ($ADTitleREG -eq $ADTitle){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ADTitle -Value $ADTitle}
    if ($ADTitleREG -eq $ADTitle){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ADTitle -Value $ADTitle}

    Не подскажите почему скрипт начинает работу после логона пользователя через 10-15 минут ?

    В ГПО настройки такие:

    • Помечено в качестве ответа Trusilya 15 апреля 2016 г. 14:28
    • Снята пометка об ответе Trusilya 15 апреля 2016 г. 14:52
    • Помечено в качестве ответа KazunEditor 16 апреля 2016 г. 16:20
    15 апреля 2016 г. 14:27

Все ответы

  • Все получилось сделать за исключением 

    1 Не могу понять как выводить мобильный ?

    2 Автоматически не ставится подпись по умолчанию в новых письмах , что не так куда смотреть ?

    Код :

    #Custom variables
    $CompanyName = ‘DOMAIN'
    $SigSource = "\\domain.ru\NETLOGON\Signatures"
    $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 = '1' #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
    $LocalSignatureFile = $LocalSignaturePath+'\'+$CompanyName+' официальная.files'
    $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()
    $ADDisplayName = $ADUser.DisplayName
    $ADEmailAddress = $ADUser.mail
    $ADTitle = $ADUser.title
    $ADTelePhoneNumber = $ADUser.TelephoneNumber
    
    #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
    #присваиваем переменные взяв значения из реестра
    $TelephoneNumberREG = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').TelephoneNumber
    $DisplayNameREG = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').DisplayName
    $EmailAddressREG = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').EmailAddress
    $ADTitleREG = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').ADTitle
    
    $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
    $FileExists =  Test-Path "$LocalSignatureFile"
    if ($SignatureVersion -eq $SigVersion -And $TelephoneNumberREG -eq $ADTelePhoneNumber -And $DisplayNameREG -eq $ADDisplayName -And $EmailAddressREG -eq $ADEmailAddress -And $ADTitleREG -eq $ADTitle -and $FileExists -eq $true) {}
    else
    {
    #Copy signature templates from domain to local Signature-folder
    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
    
    #Insert variables from Active Directory to rtf signature-file
    $MSWord = New-Object -com word.application
    $fullPath = $LocalSignaturePath+'\'+$CompanyName+'.docx'
    $MSWord.Documents.Open($fullPath)
    
    $FindText = "TelephoneNumber"
    $ReplaceText = $ADTelephoneNumber.ToString()
    $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )
    
    $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    )
    
    $MSWord.Selection.Find.Execute("Email")
    
    $MSWord.ActiveDocument.Hyperlinks.Add($MSWord.Selection.Range, "mailto:"+$ADEmailAddress.ToString(), $missing, $missing, $ADEmailAddress.ToString())
    
    $MSWord.ActiveDocument.Save()
    $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatHTML");
    [ref]$BrowserLevel = "microsoft.office.interop.word.WdBrowserLevel" -as [type]
    
    $MSWord.ActiveDocument.WebOptions.OrganizeInFolder = $true
    $MSWord.ActiveDocument.WebOptions.UseLongFileNames = $true
    $MSWord.ActiveDocument.WebOptions.BrowserLevel = $BrowserLevel::wdBrowserLevelMicrosoftInternetExplorer6
    $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+" официальная.rtf"
    $MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$saveFormat)
    
    $path = $LocalSignaturePath+'\'+$CompanyName+" официальная.txt"
    $MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$SaveFormat)    #::wdFormatText)
    $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}
    
    #проверить актуальность тел. номера
    if ($TelephoneNumberREG -eq $ADTelePhoneNumber){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name TelephoneNumber -Value $ADTelePhoneNumber}
    if ($TelephoneNumberREG -eq $ADTelePhoneNumber){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name TelephoneNumber -Value $ADTelePhoneNumber}
    
    #проверить актуальность ФИО
    if ($DisplayNameREG -eq $ADDisplayName){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name DisplayName -Value $ADDisplayName}
    if ($DisplayNameREG -eq $ADDisplayName){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name DisplayName -Value $ADDisplayName}
    
    #проверить актуальность e-mail
    if ($EmailAddressREG -eq $ADEmailAddress){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name EmailAddress -Value $ADEmailAddress}
    if ($EmailAddressREG -eq $ADEmailAddress){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name EmailAddress -Value $ADEmailAddress}
    
    #проверить актуальность должности
    if ($ADTitleREG -eq $ADTitle){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ADTitle -Value $ADTitle}
    if ($ADTitleREG -eq $ADTitle){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ADTitle -Value $ADTitle}

    Заранее благодарен !
    • Изменено Trusilya 15 апреля 2016 г. 11:33
    15 апреля 2016 г. 11:32
  • Получилось если кому интересно вот рабочий вариант:

    #Custom variables
    $CompanyName = ‘DOMAIN'
    $SigSource = "\\domain.ru\NETLOGON\Signatures"
    $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 = '1' #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
    $LocalSignatureFile = $LocalSignaturePath+'\'+$CompanyName+' официальная.files'
    $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()
    $ADDisplayName = $ADUser.DisplayName
    $ADEmailAddress = $ADUser.mail
    $ADTitle = $ADUser.title
    $ADTelePhoneNumber = $ADUser.TelephoneNumber
    $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
    #присваиваем переменные взяв значения из реестра
    $TelephoneNumberREG = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').TelephoneNumber
    $DisplayNameREG = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').DisplayName
    $EmailAddressREG = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').EmailAddress
    $ADTitleREG = (Get-ItemProperty $CompanyRegPath'\Outlook Signature Settings').ADTitle
    
    $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
    $FileExists =  Test-Path "$LocalSignatureFile"
    if ($SignatureVersion -eq $SigVersion -And $TelephoneNumberREG -eq $ADTelePhoneNumber -And $mobileREG -eq $ADmobile -And $DisplayNameREG -eq $ADDisplayName -And $EmailAddressREG -eq $ADEmailAddress -And $ADTitleREG -eq $ADTitle -and $FileExists -eq $true) {}
    else
    {
    #Copy signature templates from domain to local Signature-folder
    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
    
    #Insert variables from Active Directory to rtf signature-file
    $MSWord = New-Object -com word.application
    $fullPath = $LocalSignaturePath+'\'+$CompanyName+'.docx'
    $MSWord.Documents.Open($fullPath)
    
    $FindText = "TelephoneNumber"
    $ReplaceText = $ADTelephoneNumber.ToString()
    $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )
    
    $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    )
    
    $FindText = "mobile"
    $ReplaceText = $ADmobile.ToString()
    $MSWord.Selection.Find.Execute($FindText, $MatchCase, $MatchWholeWord,    $MatchWildcards, $MatchSoundsLike, $MatchAllWordForms, $Forward, $Wrap,    $Format, $ReplaceText, $ReplaceAll    )
    
    $MSWord.Selection.Find.Execute("Email")
    
    $MSWord.ActiveDocument.Hyperlinks.Add($MSWord.Selection.Range, "mailto:"+$ADEmailAddress.ToString(), $missing, $missing, $ADEmailAddress.ToString())
    
    $MSWord.ActiveDocument.Save()
    $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatHTML");
    [ref]$BrowserLevel = "microsoft.office.interop.word.WdBrowserLevel" -as [type]
    
    $MSWord.ActiveDocument.WebOptions.OrganizeInFolder = $true
    $MSWord.ActiveDocument.WebOptions.UseLongFileNames = $true
    $MSWord.ActiveDocument.WebOptions.BrowserLevel = $BrowserLevel::wdBrowserLevelMicrosoftInternetExplorer6
    $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+" официальная.rtf"
    $MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$saveFormat)
    
    $path = $LocalSignaturePath+'\'+$CompanyName+" официальная.txt"
    $MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$SaveFormat)    #::wdFormatText)
    $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}
    
    #проверить актуальность тел. номера
    if ($TelephoneNumberREG -eq $ADTelePhoneNumber){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name TelephoneNumber -Value $ADTelePhoneNumber}
    if ($TelephoneNumberREG -eq $ADTelePhoneNumber){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name TelephoneNumber -Value $ADTelePhoneNumber}
    
    #проверить актуальность ФИО
    if ($DisplayNameREG -eq $ADDisplayName){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name DisplayName -Value $ADDisplayName}
    if ($DisplayNameREG -eq $ADDisplayName){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name DisplayName -Value $ADDisplayName}
    
    #проверить актуальность e-mail
    if ($EmailAddressREG -eq $ADEmailAddress){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name EmailAddress -Value $ADEmailAddress}
    if ($EmailAddressREG -eq $ADEmailAddress){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name EmailAddress -Value $ADEmailAddress}
    
    #проверить актуальность должности
    if ($ADTitleREG -eq $ADTitle){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ADTitle -Value $ADTitle}
    if ($ADTitleREG -eq $ADTitle){}
    else
    {Set-ItemProperty $CompanyRegPath'\Outlook Signature Settings' -name ADTitle -Value $ADTitle}

    Не подскажите почему скрипт начинает работу после логона пользователя через 10-15 минут ?

    В ГПО настройки такие:

    • Помечено в качестве ответа Trusilya 15 апреля 2016 г. 14:28
    • Снята пометка об ответе Trusilya 15 апреля 2016 г. 14:52
    • Помечено в качестве ответа KazunEditor 16 апреля 2016 г. 16:20
    15 апреля 2016 г. 14:27