Advertisement
xs4eyes

Updated outlook signature

Apr 28th, 2016
1,173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ###############################################################
  2. # This section is to support older versions of powershell     #
  3. # and also to not be forced to invoke a command on a different#
  4. # computer or to be forced to install aditional modules       #
  5. ###############################################################
  6. Function Get-UserADObject
  7. {
  8.     [CmdletBinding(
  9.         SupportsShouldProcess=$True,
  10.         ConfirmImpact="Low"
  11.     )]
  12.     param
  13.     (
  14.         [String]$Ldap = "dc="+$env:USERDNSDOMAIN.replace(".",",dc="),        
  15.         [String]$Filter = "(&(objectCategory=person)(objectClass=user))"
  16.     )
  17.  
  18.     Begin{}
  19.  
  20.     Process
  21.     {
  22.         if ($pscmdlet.ShouldProcess($Ldap,"Get information about AD Object"))
  23.         {
  24.             $searcher=[adsisearcher]$Filter
  25.              
  26.             $Ldap = $Ldap.replace("LDAP://","")
  27.             $searcher.SearchRoot="LDAP://$Ldap"
  28.             $results=$searcher.FindAll()
  29.      
  30.             $ADObjects = @()
  31.             foreach($result in $results)
  32.             {
  33.                 [Array]$propertiesList = $result.Properties.PropertyNames
  34.                 $obj = New-Object PSObject
  35.                 foreach($property in $propertiesList)
  36.                 {  
  37.                     $obj | add-member -membertype noteproperty -name $property -value ([string]$result.Properties.Item($property))
  38.                 }
  39.                 $ADObjects += $obj
  40.             }
  41.        
  42.             Return $ADObjects
  43.         }
  44.     }
  45.      
  46.     End{}
  47. }
  48. $info = Get-UserADObject -Filter "samaccountname=$env:username"
  49.  
  50.   # Set variables - gets the ad information from adsisearch so no need to load the activedirectory module
  51.   $HTMTemplate = (Get-Content "Location To HTM Template")
  52.   $RTFTemplate = (Get-Content "Location To RTF Template")
  53.   $TXTTemplate = (Get-Content "Location To TXT Template")
  54.  
  55.   # The $userDomain variable - we had soem accounts that the user had the domain added on the end,
  56.   # this copies the files there if it exists.
  57.   $userDomain = $env:USERNAME + ".$env:USERDOMAIN"
  58.   $versions = @('11.0', '12.0', '13.0', '14.0', '15.0', '16.0')
  59.   $Name =  $info.name
  60.   $Email = $info.mail
  61.   $Title = $info.title
  62.   $Phone = $info.telephonenumber
  63.   $uname = $info.name
  64.   $notes = $info.info
  65.   $Cell = $info.mobile
  66.   # addes the Professional Designation
  67.     if($notes -ne $null){$name += ", $notes"}
  68.     if ($Cell -ne $null){$Phone += " - Mobile: $Cell"}
  69.  
  70. Function Set-OutlookSignature
  71. {
  72.   <########################################################
  73.       #   Email Signature setup                              #  
  74.       #   Get the logged in user name                        #
  75.       #   Get the AD account information from that username  #
  76.       #   Set the variables needed                           #  
  77.    ########################################################>
  78.  
  79.  
  80.   # Use a template HTM file and auto fill. Create folder and the files for the new signature.
  81.   # You need all three different file types for the three different signature types
  82.   $HTMTemplate |
  83.   Foreach-Object { $_ -replace '"Name"', "$Name" `
  84.     -replace '"Title"', "$Title" `
  85.     -replace '"Email"', "$Email" `
  86.   -replace '"EXT"', "$Phone"}|
  87.   Set-Content "c:\Users\$env:username\EmailSig$env:username.htm"
  88.  
  89.   # for the RTF signature
  90.   $RTFTemplate |
  91.   Foreach-Object { $_ -replace '"Name"', "$Name" `
  92.     -replace '"Title"', "$Title" `
  93.     -replace '"Email"', "$Email" `
  94.     -replace '"EXT"', "$Phone" `
  95.   -replace '"Username"', "$uname"}|
  96.   Set-Content "c:\Users\$env:username\EmailSig$env:username.rtf"
  97.  
  98.   # for the txt signature
  99.   $TXTTemplate |
  100.   Foreach-Object { $_ -replace '"Name"', "$Name" `
  101.     -replace '"Title"', "$Title" `
  102.     -replace '"Email"', "$Email" `
  103.   -replace '"EXT"', "$Phone"}|
  104.   Set-Content "c:\Users\$env:username\EmailSig$env:username.txt"
  105.  
  106.  
  107.   # Test and set the reg keys for new and reply messages.
  108.   # This also removes the option to change the signature.
  109.  
  110.   foreach ($version in $versions){if ( test-path "HKCU:\SOFTWARE\MICROSOFT\OFFICE\$version\COMMON\MAILSETTINGS" ) {
  111.       get-item -path HKCU:\SOFTWARE\MICROSOFT\OFFICE\$version\COMMON\MAILSETTINGS | new-Itemproperty -name NewSignature -value $env:USERNAME -propertytype string -force
  112.       get-item -path HKCU:\SOFTWARE\MICROSOFT\OFFICE\$version\COMMON\MAILSETTINGS | new-Itemproperty -name ReplySignature -value $env:USERNAME -propertytype string -force
  113.         }
  114.     }
  115.  
  116.  
  117.  
  118.   #Create and set these reg keys
  119.  
  120.       foreach ($version in $versions){ if (test-path "HKCU:\Software\Microsoft\Office\\$version\Common\General") {
  121.       get-item -path HKCU:\Software\Microsoft\Office\$version\Common\General | new-Itemproperty -name Signatures -value $env:username -propertytype string -force
  122.       $key = Get-ItemProperty -Path HKCU:\Software\Microsoft\Office\$version\Common\General -name Royal-First-Run
  123.         if ($key -eq $null){
  124.             get-item -path HKCU:\Software\Microsoft\Office\$version\Common\\General | new-Itemproperty -name Royal-First-Run -value "1" -propertytype string -force
  125.             get-item -path HKCU:\SOFTWARE\MICROSOFT\OFFICE\$version\OUTLOOK\SETUP | Remove-ItemProperty -name First-Run }
  126.             }
  127.         }
  128.  
  129.   # Copy the signature files to the correct location for the install type
  130.  
  131.   if ((Test-Path C:\users\$userDomain\AppData\Roaming\Microsoft\Signatures\) -eq $true){
  132.  
  133.     Copy-item "C:\Users\$env:username\EmailSig$env:username.htm" C:\Users\$userDomain\AppData\Roaming\Microsoft\Signatures\$userDomain.htm
  134.     Copy-Item "C:\Users\$env:username\EmailSig$env:username.rtf" C:\Users\$userDomain\AppData\Roaming\Microsoft\Signatures\$userDomain.rtf
  135.     Copy-Item "C:\Users\$env:username\EmailSig$env:username.txt" C:\Users\$userDomain\AppData\Roaming\Microsoft\Signatures\$userDomain.txt
  136.     }
  137.  
  138.  
  139.     if ((test-path -path "C:\Users\$env:username\AppData\Roaming\Microsoft\$env:username") -eq $false){
  140.         New-Item -ItemType Directory -path "C:\Users\$env:username\AppData\Roaming\Microsoft\$env:username"
  141.     }
  142.        
  143.    
  144.     if ((test-path -path "C:\Users\$env:username\AppData\Roaming\Microsoft\Signatures\") -eq $false){
  145.         New-Item -ItemType Directory -path "C:\Users\$env:username\AppData\Roaming\Microsoft\Signatures\"
  146.     }
  147.        
  148.     Copy-item "C:\Users\$env:username\EmailSig$env:username.htm" C:\Users\$env:username\AppData\Roaming\Microsoft\$env:username\$env:username.htm
  149.     Copy-Item "C:\Users\$env:username\EmailSig$env:username.rtf" C:\Users\$env:username\AppData\Roaming\Microsoft\$env:username\$env:username.rtf
  150.     Copy-Item "C:\Users\$env:username\EmailSig$env:username.txt" C:\Users\$env:username\AppData\Roaming\Microsoft\$env:username\$env:username.txt
  151.   ##
  152.     Copy-item "C:\Users\$env:username\EmailSig$env:username.htm" C:\Users\$env:username\AppData\Roaming\Microsoft\Signatures\$env:username.htm
  153.     Copy-Item "C:\Users\$env:username\EmailSig$env:username.rtf" C:\Users\$env:username\AppData\Roaming\Microsoft\Signatures\$env:username.rtf
  154.     Copy-Item "C:\Users\$env:username\EmailSig$env:username.txt" C:\Users\$env:username\AppData\Roaming\Microsoft\Signatures\$env:username.txt
  155.  
  156.  
  157.   #################################################
  158.  
  159.   #
  160.   <#
  161.       To enable the ability to change signature you will need to remove
  162.       the following reg keys
  163.       HKCU:\\SOFTWARE\\MICROSOFT\\OFFICE\\14.0\\COMMON\\MAILSETTINGS\\NEWSIGNATURE
  164.       HKCU:\\SOFTWARE\\MICROSOFT\\OFFICE\\14.0\\COMMON\\MAILSETTINGS\\REPLYSIGNATURE
  165.       THEY SHOULD BE SET TO "REG_SZ" "*USERNAME*"
  166.   #>
  167. }
  168.  
  169. Set-OutlookSignature
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement