############################################################### # This section is to support older versions of powershell # and also to not be forced to invoke a command on a different # computer or to be forced to install aditional modules on # users computers ############################################################### Function Get-UserADObject { [CmdletBinding( SupportsShouldProcess=$True, ConfirmImpact="Low" )] param ( [String]$Ldap = "dc="+$env:USERDNSDOMAIN.replace(".",",dc="), [String]$Filter = "(&(objectCategory=person)(objectClass=user))" ) Begin{} Process { if ($pscmdlet.ShouldProcess($Ldap,"Get information about AD Object")) { $searcher=[adsisearcher]$Filter $Ldap = $Ldap.replace("LDAP://","") $searcher.SearchRoot="LDAP://$Ldap" $results=$searcher.FindAll() $ADObjects = @() foreach($result in $results) { [Array]$propertiesList = $result.Properties.PropertyNames $obj = New-Object PSObject foreach($property in $propertiesList) { $obj | add-member -membertype noteproperty -name $property -value ([string]$result.Properties.Item($property)) } $ADObjects += $obj } Return $ADObjects } } End{} } $info = Get-UserADObject -Filter "samaccountname=$env:username" # Set variables - gets the ad information from adsisearch so no need to load the activedirectory module $HTMTemplate = (Get-Content "Path to HTM template") $RTFTemplate = (Get-Content "Path to RTF Template") $TXTTemplate = (Get-Content "Path to TXT Template") $userDomain = $env:USERNAME + ".$env:USERDOMAIN" $versions = @('11.0', '12.0', '13.0', '14.0', '15.0', '16.0') $Name = $info.displayname $Email = $info.mail $Title = $info.title $Phone = $info.telephonenumber $uname = $info.name $notes = $info.info # addes the Professional Designation if($notes -ne $null){$name += ", $notes"} if ($Cell -ne $null){$Phone += " - Mobile: $Cell"} Function Set-OutlookSignature { <######################################################## # Email Signature setup # Get the logged in user name # Get the AD account information from that username # Set the variables needed ########################################################> # Use a template HTM file and auto fill. Create folder and the files for the new signature. # You need all three different file types for the three different signature types $HTMTemplate | Foreach-Object { $_ -replace '"Name"', "$Name" ` -replace '"Title"', "$Title" ` -replace '"Email"', "$Email" ` -replace '"EXT"', "$Phone"}| Set-Content "c:\EmailSig$env:username.htm" # for the RTF signature $RTFTemplate | Foreach-Object { $_ -replace '"Name"', "$Name" ` -replace '"Title"', "$Title" ` -replace '"Email"', "$Email" ` -replace '"EXT"', "$Phone" ` -replace '"Username"', "$uname"}| Set-Content "c:\EmailSig$env:username.rtf" # for the txt signature $TXTTemplate | Foreach-Object { $_ -replace '"Name"', "$Name" ` -replace '"Title"', "$Title" ` -replace '"Email"', "$Email" ` -replace '"EXT"', "$Phone"}| Set-Content "c:\EmailSig$env:username.txt" # Test and set the reg keys for new and reply messages. # This also removes the option to change the signature. foreach ($version in $versions){if ( test-path "HKCU:\SOFTWARE\MICROSOFT\OFFICE\$version\COMMON\MAILSETTINGS" ) { get-item -path HKCU:\SOFTWARE\MICROSOFT\OFFICE\$version\COMMON\MAILSETTINGS | new-Itemproperty -name NewSignature -value $env:USERNAME -propertytype string -force get-item -path HKCU:\SOFTWARE\MICROSOFT\OFFICE\$version\COMMON\MAILSETTINGS | new-Itemproperty -name ReplySignature -value $env:USERNAME -propertytype string -force } } # For some office 2016 it installed to HKLM instead of HKCU, Added this path to cover those instances. foreach ($version in $versions){if ( test-path "HKCU:\SOFTWARE\MICROSOFT\OFFICE\$version\COMMON\MAILSETTINGS" ) { get-item -path HKLM:\SOFTWARE\MICROSOFT\OFFICE\$version\COMMON\MAILSETTINGS | new-Itemproperty -name NewSignature -value $env:USERNAME -propertytype string -force get-item -path HKLM:\SOFTWARE\MICROSOFT\OFFICE\$version\COMMON\MAILSETTINGS | new-Itemproperty -name ReplySignature -value $env:USERNAME -propertytype string -force } } #Create and set these reg keys foreach ($version in $versions){ if (test-path "HKCU:\Software\Microsoft\Office\\$version\Common\General") { get-item -path HKCU:\Software\Microsoft\Office\$version\Common\General | new-Itemproperty -name Signatures -value $env:username -propertytype string -force $key = Get-ItemProperty -Path HKCU:\Software\Microsoft\Office\$version\Common\General -name Royal-First-Run if ($key -eq $null){ get-item -path HKCU:\Software\Microsoft\Office\$version\Common\\General | new-Itemproperty -name Royal-First-Run -value "1" -propertytype string -force get-item -path HKCU:\SOFTWARE\MICROSOFT\OFFICE\$version\OUTLOOK\SETUP | Remove-ItemProperty -name First-Run } } } # For some office 2016 it installed to HKLM instead of HKCU, Added this path to cover those instances. foreach ($version in $versions){ if (test-path "HKCU:\Software\Microsoft\Office\\$version\Common\General") { get-item -path HKCU:\Software\Microsoft\Office\$version\Common\General | new-Itemproperty -name Signatures -value $env:username -propertytype string -force $key = Get-ItemProperty -Path HKCU:\Software\Microsoft\Office\$version\Common\General -name Royal-First-Run if ($key -eq $null){ get-item -path HKCU:\Software\Microsoft\Office\$version\Common\\General | new-Itemproperty -name Royal-First-Run -value "1" -propertytype string -force get-item -path HKCU:\SOFTWARE\MICROSOFT\OFFICE\$version\OUTLOOK\SETUP | Remove-ItemProperty -name First-Run } } } # Copy the signature files to the correct location for the install type Copy-item "C:\EmailSig$env:username.htm" C:\Users\$userDomain\AppData\Roaming\Microsoft\Signatures\$userDomain.htm Copy-Item "C:\EmailSig$env:username.rtf" C:\Users\$userDomain\AppData\Roaming\Microsoft\Signatures\$userDomain.rtf Copy-Item "C:\EmailSig$env:username.txt" C:\Users\$userDomain\AppData\Roaming\Microsoft\Signatures\$userDomain.txt if ((test-path -path "C:\Users\$env:username\AppData\Roaming\Microsoft\$env:username") -eq $false){ New-Item -ItemType Directory -path "C:\Users\$env:username\AppData\Roaming\Microsoft\$env:username" } if ((test-path -path "C:\Users\$env:username\AppData\Roaming\Microsoft\Signatures\") -eq $false){ New-Item -ItemType Directory -path "C:\Users\$env:username\AppData\Roaming\Microsoft\Signatures\" } Copy-item "C:\EmailSig$env:username.htm" C:\Users\$env:username\AppData\Roaming\Microsoft\$env:username\$env:username.htm Copy-Item "C:\EmailSig$env:username.rtf" C:\Users\$env:username\AppData\Roaming\Microsoft\$env:username\$env:username.rtf Copy-Item "C:\EmailSig$env:username.txt" C:\Users\$env:username\AppData\Roaming\Microsoft\$env:username\$env:username.txt ## Copy-item "C:\EmailSig$env:username.htm" C:\Users\$env:username\AppData\Roaming\Microsoft\Signatures\$env:username.htm Copy-Item "C:\EmailSig$env:username.rtf" C:\Users\$env:username\AppData\Roaming\Microsoft\Signatures\$env:username.rtf Copy-Item "C:\EmailSig$env:username.txt" C:\Users\$env:username\AppData\Roaming\Microsoft\Signatures\$env:username.txt ################################################# # <# To enable the ability to change signature you will need to remove the following reg keys HKCU:\\SOFTWARE\\MICROSOFT\\OFFICE\\14.0\\COMMON\\MAILSETTINGS\\NEWSIGNATURE HKCU:\\SOFTWARE\\MICROSOFT\\OFFICE\\14.0\\COMMON\\MAILSETTINGS\\REPLYSIGNATURE THEY SHOULD BE SET TO "REG_SZ" "*USERNAME*" #> } Set-OutlookSignature