Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #############################################
- #### Get AD information for current user ####
- #############################################
- $UserName = $env:username
- $signatures = "$env:APPDATA\Microsoft\Signatures"
- $Filter = "(&(objectCategory=User)(samAccountName=$UserName))"
- $Searcher = New-Object System.DirectoryServices.DirectorySearcher
- $Searcher.Filter = $Filter
- $ADUserPath = $Searcher.FindOne()
- $ADUser = $ADUserPath.GetDirectoryEntry()
- $ADDisplayName = $ADUser.DisplayName
- $ADDeparment = $ADUser.department
- $ADEmailAddress = $ADUser.mail
- $ADEmailto = "mailto:$ADEmailAddress"
- $ADTitle = $ADUser.title
- $ADDescription = $ADUser.description
- $ADMobile = "Mob: " + $ADUser.mobile.Substring(0,4) + " " + $ADUser.mobile.Substring(4,4) + " " + $ADUser.mobile.Substring(8)
- $ADPhone = "Tel: " + $ADUser.telephonenumber.Substring(0,4) + " " + $ADUser.telephonenumber.Substring(4,3) + " " + $ADUser.telephonenumber.Substring(7)
- $ADStreetAddress = $ADUserPath.streetaddress
- $ADOffice = $ADuser.physicalDeliveryOfficeName
- if ($ADOffice -like "Tallinn") {$Adoffice = "Tallina mnt 15, 12345 Tallinn, Eesti"}
- if ($ADOffice -like "Tartu") {$Adoffice = "Tartu mnt 16, 12345 Tartu, Eesti"}
- #########################################
- #### Create Outlook Signature folder ####
- #########################################
- $sigfoldercheck = (Test-Path $signatures)
- if ($sigfoldercheck -like "False"){New-Item $signatures -ItemType Directory}
- ##########################################
- #### Check for Active Outlook Profile ####
- ##########################################
- $checkprofile = Test-Path "HKCU:\HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Profiles\Outlook"
- if ($checkprofile -like "False") {exit}
- ##############################
- #### Clean if no REG Flag ####
- ##############################
- $RegFlagCheck = [bool] (Get-ItemProperty "HKCU:\HKEY_CURRENT_USER\Software\VERSIOONIHALDUS\Outlook Signatuur" | select "Signatuur")
- if ($RegFlagCheck -eq "True") {exit}
- else {
- Get-ChildItem -Path "$signatures\Signatuur*" | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
- ######################################
- #### Build signature from AD DATA ####
- ######################################
- $objWord = New-object -comobject Word.Application
- $objWord.Visible = $False
- $objDoc = $objWord.Documents.Open("enter your UNC path here")
- $objSelection = $objWord.Selection
- # Intro
- $text = "Lugupidamisega"
- $objSelection.TypeText($text)
- $objSelection.TypeParagraph()
- $objSelection.TypeParagraph()
- # Break
- $text = "______________________________"
- $objSelection.TypeText($text)
- $objSelection.TypeParagraph()
- # UserName
- if ($ADDisplayName) {$objSelection.TypeText($ADDisplayName)
- $objSelection.TypeParagraph()}
- # JobTitle
- if ($ADTitle) {$objSelection.TypeText($ADTitle)
- $objSelection.TypeParagraph()}
- # Deparment
- if ($ADDeparment) {$objSelection.TypeText($ADDeparment)
- $objSelection.TypeParagraph()}
- # CompanyName
- $text = "Contoso Corp"
- $objSelection.TypeText($text)
- $objSelection.TypeParagraph()
- # OfficeAdress
- if ($ADOffice) {$objSelection.TypeText($ADOffice)
- $objSelection.TypeParagraph()}
- # MobilePhone
- if ($ADMobile) {$objSelection.TypeText($ADMobile)
- $objSelection.TypeParagraph()}
- # OfficePhone
- if ($ADPhone) {$objSelection.TypeText($ADPhone)
- $objSelection.TypeParagraph()}
- # E-Mail
- if ($ADEmailAddress) {$hlink = $objSelection.Hyperlinks.Add($objSelection.Range,"$ADEmailto",$False,$False,"$ADEmailAddress")
- $hlink.Range.Font.Size = 8
- $hlink.Range.Font.Name = "Verdana"
- $objSelection.TypeParagraph()}
- $objSelection.TypeParagraph()
- # CompnayWebPage
- $hlink = $objSelection.Hyperlinks.Add($objSelection.Range,“http://www.contoso.com",$False,$False,“www.contoso.com”)
- $hlink.Range.Font.Size = 8
- $hlink.Range.Font.Name = "Verdana"
- $objSelection.TypeParagraph()
- # CompanyFB
- $hlink = $objSelection.Hyperlinks.Add($objSelection.Range,"https://www.facebook.com/contoso",$False,$False,“www.facebook.com/contoso”)
- $hlink.Range.Font.Size = 8
- $hlink.Range.Font.Name = "Verdana"
- $objSelection.TypeParagraph()
- $objSelection.TypeParagraph()
- ##########################################################
- #### Save Signature files to Outlook Signature Folder ####
- ##########################################################
- # Save .HTM to signatures folder
- $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatHTML");
- $path = "$signatures\Signatuur.htm"
- $objword.ActiveDocument.saveas([ref]$path, [ref]$saveFormat)
- # Save .RTF to signatures folder
- $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatRTF");
- $path = "$signatures\Signatuur.rtf"
- $objword.ActiveDocument.saveas([ref]$path, [ref]$saveFormat)
- # Save .TXT to signatures folder
- $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatText");
- $path = "$signatures\Signatuur.txt"
- $objword.ActiveDocument.saveas([ref]$path, [ref]$saveFormat)
- ##########################################
- #### Set Signature options in Outlook ####
- ##########################################
- $EmailOptions = $objWord.EmailOptions
- $EmailSignature = $EmailOptions.EmailSignature
- $EmailSignature.NewMessageSignature = “Signatuur”
- # $EmailSignature.ReplyMessageSignature = “Signatuur”
- $objWord.quit()
- ######################
- #### Set REG Flag ####
- ######################
- $root = "HKCU:\HKEY_CURRENT_USER\SOFTWARE\VERSIOONIHALDUS\"
- $program = "Outlook Signatuur"
- $rootcheck = Test-Path -Path $root
- $programcheck = Test-Path -Path $root$program
- If ($rootcheck -like "False") {New-Item -Path $root}
- If ($programcheck -like "False") {New-Item -Path $root$program}
- New-ItemProperty -Path $root$program -Name "Signatuur" -PropertyType STRING -Value 1
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement