Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #A template for the signatures can be downloaded on my google drive at:
- #https://drive.google.com/open?id=0B2kaqHUWZdXxNXlHYU1EZnFJVTg
- #If you are creating your own template, make sure you create: html, rtf and txt versions.
- #You can easily deploy this powershell script via Group Policy, then configure user settings to run this script on 'logon'.
- #This script creates the temp file which the signatures are populated, but I'm working on it to get the correct path for Outlook
- #depending on the registry entries etc.
- $serverName = "W17BS-SVR01"
- $user = $env:username
- #Paths used for copying from share to temp, then to Outlook signature
- $shareLocation = "\\$serverName\Share\Outlook_Signature_Templates\Standard"
- $tempPath = "C:\Users\$user\Documents\Temp-ps-created"
- $finalPath = "C:\Users\$user\Documents\final-path"
- #Final path should be OUTLOOK signature location, instead of hard scripting it would
- #be better to find the registery to find out which version of office + normally located in
- #Appdata, so using $env:appdata would be preferred...
- $filter = "(&(objectCategory=User)(samAccountName=$user))"
- #Directory Searcher allows us to perform queries against AD.
- $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
- $objSearcher.Filter = $filter #Can use LDAP:\\ filter but above is neater..
- $objPath = $objSearcher.FindOne() #Assuming 1 entry for this username, will return to our variable
- $objUser = $objPath.GetDirectoryEntry() #Returns entry relevant to $objPath
- #Populate variables with simple LDAP attributes. Can be found at with a simple google search.
- $name = $objUser.name
- $jobtitle = $objUser.title
- $mobile = $objUser.mobile
- $mail = $objUser.mail
- $extension = $objUser.pager
- #Copy the signaute template to a temp folder
- #In my situation, I would have this signature template on a share and then
- #copy it to the users C:\ documents folder as a temp store location to change variables before moving it
- #to the final location (appdata -> office16 -> outlook -> signatures)...
- if (Test-Path $tempPath)
- {
- Write-Host "Temp path exists! Deleting..."
- Remove-Item -Recurse -Force $tempPath
- Copy-Item $shareLocation -Destination "$tempPath\Standard" -Recurse -Force -Container
- } else
- {
- Write-Host "Temp path doesnt exist!"
- Copy-Item $shareLocation -Destination "$tempPath\Standard" -Recurse -Force -Container
- }
- #3 types of files in an outlook signature. HTML, rich text and text formats. Best to design these in WORD since
- #outlook can give some bad results in regards of formatting signatures etc...
- #HTML
- (Get-Content "$tempPath\Standard\Standard.htm") | Foreach-Object {
- $_ -replace '%fullname%', $name `
- -replace '%jobtitle%', $jobtitle `
- -replace '%mobile%', $mobile `
- -replace '%mail%', $mail `
- -replace '%extension%', $extension
- } | Set-Content "$tempPath\Standard\Standard.htm" -Force
- #RTF
- (Get-Content "$tempPath\Standard\Standard.rtf") | Foreach-Object {
- $_ -replace '%fullname%', $name `
- -replace '%jobtitle%', $jobtitle `
- -replace '%mobile%', $mobile `
- -replace '%mail%', $mail `
- -replace '%extension%', $extension
- } | Set-Content "$tempPath\Standard\Standard.rtf" -Force
- #TXT
- (Get-Content "$tempPath\Standard\Standard.txt") | Foreach-Object {
- $_ -replace '%fullname%', $name `
- -replace '%jobtitle%', $jobtitle `
- -replace '%mobile%', $mobile `
- -replace '%mail%', $mail `
- -replace '%extension%', $extension
- } | Set-Content "$tempPath\Standard\Standard.txt" -Force
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement