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