Advertisement
BrandonSpendlove

Powershell - Simple Outlook Signature deployment

Oct 18th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #A template for the signatures can be downloaded on my google drive at:
  2. #https://drive.google.com/open?id=0B2kaqHUWZdXxNXlHYU1EZnFJVTg
  3. #If you are creating your own template, make sure you create: html, rtf and txt versions.
  4.  
  5. #You can easily deploy this powershell script via Group Policy, then configure user settings to run this script on 'logon'.
  6. #This script creates the temp file which the signatures are populated, but I'm working on it to get the correct path for Outlook
  7. #depending on the registry entries etc.
  8.  
  9. $serverName = "W17BS-SVR01"
  10. $user = $env:username
  11.  
  12. #Paths used for copying from share to temp, then to Outlook signature
  13. $shareLocation = "\\$serverName\Share\Outlook_Signature_Templates\Standard"
  14. $tempPath = "C:\Users\$user\Documents\Temp-ps-created"
  15. $finalPath = "C:\Users\$user\Documents\final-path"
  16. #Final path should be OUTLOOK signature location, instead of hard scripting it would
  17. #be better to find the registery to find out which version of office + normally located in
  18. #Appdata, so using $env:appdata would be preferred...
  19.  
  20. $filter = "(&(objectCategory=User)(samAccountName=$user))"
  21.  
  22. #Directory Searcher allows us to perform queries against AD.
  23. $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
  24. $objSearcher.Filter = $filter #Can use LDAP:\\ filter but above is neater..
  25.  
  26.  
  27. $objPath = $objSearcher.FindOne() #Assuming 1 entry for this username, will return to our variable
  28. $objUser = $objPath.GetDirectoryEntry() #Returns entry relevant to $objPath
  29.  
  30. #Populate variables with simple LDAP attributes. Can be found at with a simple google search.
  31. $name = $objUser.name
  32. $jobtitle = $objUser.title
  33. $mobile = $objUser.mobile
  34. $mail = $objUser.mail
  35. $extension = $objUser.pager
  36.  
  37. #Copy the signaute template to a temp folder
  38. #In my situation, I would have this signature template on a share and then
  39. #copy it to the users C:\ documents folder as a temp store location to change variables before moving it
  40. #to the final location (appdata -> office16 -> outlook -> signatures)...
  41. if (Test-Path $tempPath)
  42. {
  43.     Write-Host "Temp path exists! Deleting..."
  44.     Remove-Item -Recurse -Force $tempPath
  45.     Copy-Item $shareLocation -Destination "$tempPath\Standard" -Recurse -Force -Container
  46. } else
  47. {
  48.     Write-Host "Temp path doesnt exist!"
  49.     Copy-Item $shareLocation -Destination "$tempPath\Standard" -Recurse -Force -Container
  50. }
  51.  
  52. #3 types of files in an outlook signature. HTML, rich text and text formats. Best to design these in WORD since
  53. #outlook can give some bad results in regards of formatting signatures etc...
  54. #HTML
  55. (Get-Content "$tempPath\Standard\Standard.htm") | Foreach-Object {
  56.     $_ -replace '%fullname%', $name `
  57.        -replace '%jobtitle%', $jobtitle `
  58.        -replace '%mobile%', $mobile `
  59.        -replace '%mail%', $mail `
  60.        -replace '%extension%', $extension
  61.     } | Set-Content "$tempPath\Standard\Standard.htm" -Force
  62.  
  63. #RTF
  64. (Get-Content "$tempPath\Standard\Standard.rtf") | Foreach-Object {
  65.     $_ -replace '%fullname%', $name `
  66.        -replace '%jobtitle%', $jobtitle `
  67.        -replace '%mobile%', $mobile `
  68.        -replace '%mail%', $mail `
  69.        -replace '%extension%', $extension
  70.     } | Set-Content "$tempPath\Standard\Standard.rtf" -Force
  71.  
  72. #TXT
  73. (Get-Content "$tempPath\Standard\Standard.txt") | Foreach-Object {
  74.     $_ -replace '%fullname%', $name `
  75.        -replace '%jobtitle%', $jobtitle `
  76.        -replace '%mobile%', $mobile `
  77.        -replace '%mail%', $mail `
  78.        -replace '%extension%', $extension
  79.     } | Set-Content "$tempPath\Standard\Standard.txt" -Force
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement