Advertisement
Guest User

Untitled

a guest
Dec 5th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #############################################
  2. #### Get AD information for current user ####
  3. #############################################
  4. $UserName = $env:username
  5. $signatures = "$env:APPDATA\Microsoft\Signatures"
  6. $Filter = "(&(objectCategory=User)(samAccountName=$UserName))"
  7. $Searcher = New-Object System.DirectoryServices.DirectorySearcher
  8. $Searcher.Filter = $Filter
  9. $ADUserPath = $Searcher.FindOne()
  10. $ADUser = $ADUserPath.GetDirectoryEntry()
  11. $ADDisplayName = $ADUser.DisplayName
  12. $ADDeparment = $ADUser.department
  13. $ADEmailAddress = $ADUser.mail
  14. $ADEmailto = "mailto:$ADEmailAddress"
  15. $ADTitle = $ADUser.title
  16. $ADDescription = $ADUser.description
  17. $ADMobile = "Mob: " + $ADUser.mobile.Substring(0,4) + " " + $ADUser.mobile.Substring(4,4) + " " + $ADUser.mobile.Substring(8)
  18. $ADPhone = "Tel: " + $ADUser.telephonenumber.Substring(0,4) + " " + $ADUser.telephonenumber.Substring(4,3) + " " + $ADUser.telephonenumber.Substring(7)
  19. $ADStreetAddress = $ADUserPath.streetaddress
  20. $ADOffice = $ADuser.physicalDeliveryOfficeName
  21. if ($ADOffice -like "Tallinn") {$Adoffice = "Tallina mnt 15, 12345 Tallinn, Eesti"}
  22. if ($ADOffice -like "Tartu") {$Adoffice = "Tartu mnt 16, 12345 Tartu, Eesti"}
  23. #########################################
  24. #### Create Outlook Signature folder ####
  25. #########################################
  26. $sigfoldercheck = (Test-Path $signatures)
  27. if ($sigfoldercheck -like "False"){New-Item $signatures -ItemType Directory}
  28. ##########################################
  29. #### Check for Active Outlook Profile ####
  30. ##########################################
  31. $checkprofile = Test-Path "HKCU:\HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Profiles\Outlook"
  32. if ($checkprofile -like "False") {exit}
  33. ##############################
  34. #### Clean if no REG Flag ####
  35. ##############################
  36. $RegFlagCheck = [bool] (Get-ItemProperty "HKCU:\HKEY_CURRENT_USER\Software\VERSIOONIHALDUS\Outlook Signatuur" | select "Signatuur")
  37. if ($RegFlagCheck -eq "True") {exit}
  38. else {
  39. Get-ChildItem -Path "$signatures\Signatuur*" | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
  40. ######################################
  41. #### Build signature from AD DATA ####
  42. ######################################
  43. $objWord = New-object -comobject Word.Application  
  44. $objWord.Visible = $False
  45. $objDoc = $objWord.Documents.Open("enter your UNC path here")  
  46. $objSelection = $objWord.Selection
  47. # Intro
  48. $text = "Lugupidamisega"
  49. $objSelection.TypeText($text)
  50. $objSelection.TypeParagraph()
  51. $objSelection.TypeParagraph()
  52. # Break
  53. $text = "______________________________"
  54. $objSelection.TypeText($text)
  55. $objSelection.TypeParagraph()
  56. # UserName
  57. if ($ADDisplayName) {$objSelection.TypeText($ADDisplayName)
  58. $objSelection.TypeParagraph()}
  59. # JobTitle
  60. if ($ADTitle) {$objSelection.TypeText($ADTitle)
  61. $objSelection.TypeParagraph()}
  62. # Deparment
  63. if ($ADDeparment) {$objSelection.TypeText($ADDeparment)
  64. $objSelection.TypeParagraph()}
  65. # CompanyName
  66. $text = "Contoso Corp"
  67. $objSelection.TypeText($text)
  68. $objSelection.TypeParagraph()
  69. # OfficeAdress
  70. if ($ADOffice) {$objSelection.TypeText($ADOffice)
  71. $objSelection.TypeParagraph()}
  72. # MobilePhone
  73. if ($ADMobile) {$objSelection.TypeText($ADMobile)
  74. $objSelection.TypeParagraph()}
  75. # OfficePhone
  76. if ($ADPhone) {$objSelection.TypeText($ADPhone)
  77. $objSelection.TypeParagraph()}
  78. # E-Mail
  79. if ($ADEmailAddress) {$hlink = $objSelection.Hyperlinks.Add($objSelection.Range,"$ADEmailto",$False,$False,"$ADEmailAddress")
  80. $hlink.Range.Font.Size = 8
  81. $hlink.Range.Font.Name = "Verdana"
  82. $objSelection.TypeParagraph()}
  83. $objSelection.TypeParagraph()
  84. # CompnayWebPage
  85. $hlink = $objSelection.Hyperlinks.Add($objSelection.Range,“http://www.contoso.com",$False,$False,“www.contoso.com”)
  86. $hlink.Range.Font.Size = 8
  87. $hlink.Range.Font.Name = "Verdana"
  88. $objSelection.TypeParagraph()
  89. # CompanyFB
  90. $hlink = $objSelection.Hyperlinks.Add($objSelection.Range,"https://www.facebook.com/contoso",$False,$False,“www.facebook.com/contoso”)
  91. $hlink.Range.Font.Size = 8
  92. $hlink.Range.Font.Name = "Verdana"
  93. $objSelection.TypeParagraph()
  94. $objSelection.TypeParagraph()
  95. ##########################################################
  96. #### Save Signature files to Outlook Signature Folder ####
  97. ##########################################################
  98. # Save .HTM to signatures folder
  99. $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatHTML");
  100. $path = "$signatures\Signatuur.htm"
  101. $objword.ActiveDocument.saveas([ref]$path, [ref]$saveFormat)
  102. # Save .RTF to signatures folder
  103. $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatRTF");
  104. $path = "$signatures\Signatuur.rtf"
  105. $objword.ActiveDocument.saveas([ref]$path, [ref]$saveFormat)
  106. # Save .TXT to signatures folder
  107. $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatText");
  108. $path = "$signatures\Signatuur.txt"
  109. $objword.ActiveDocument.saveas([ref]$path, [ref]$saveFormat)
  110. ##########################################
  111. #### Set Signature options in Outlook ####
  112. ##########################################
  113. $EmailOptions = $objWord.EmailOptions
  114. $EmailSignature = $EmailOptions.EmailSignature
  115. $EmailSignature.NewMessageSignature = “Signatuur”
  116. # $EmailSignature.ReplyMessageSignature = “Signatuur”
  117. $objWord.quit()
  118. ######################
  119. #### Set REG Flag ####
  120. ######################
  121. $root = "HKCU:\HKEY_CURRENT_USER\SOFTWARE\VERSIOONIHALDUS\"
  122. $program = "Outlook Signatuur"
  123. $rootcheck = Test-Path -Path $root
  124. $programcheck = Test-Path -Path $root$program
  125. If ($rootcheck -like "False") {New-Item -Path $root}
  126. If ($programcheck -like "False") {New-Item -Path $root$program}
  127. New-ItemProperty -Path $root$program -Name "Signatuur" -PropertyType STRING -Value 1
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement