· 4 years ago · Jul 31, 2021, 08:02 AM
1#thought I would have more time to make something beautiful for the CTF, but, just don't have the time, so, bastardising https://github.com/jseerden/IntuneEmailSignatureManagement instead :( Full credit to the original author.
2#combining also hints from https://office365itpros.com/2020/02/19/updating-outlook-signature-powershell/
3#using first lot to pull info from AD easily, then second to create the html to keep this all in one file...
4
5# Win32 app runs PowerShell in 32-bit by default. AzureAD module requires PowerShell in 64-bit, so we are going to trigger a rerun in 64-bit.
6if ($env:PROCESSOR_ARCHITEW6432 -eq "AMD64") {
7 try {
8 & "$env:WINDIR\SysNative\WindowsPowershell\v1.0\PowerShell.exe" -File $PSCommandPath
9 }
10 catch {
11 throw "Failed to start $PSCommandPath"
12 }
13 exit
14}
15
16Start-Transcript -Path "$($env:TEMP)\IntuneSignatureManagerForOutlook-log.txt" -Force
17
18# Install AzureAD module to retrieve the user information
19Install-Module -Name AzureAD -Scope CurrentUser -Force
20
21# Leverage Single Sign-on to sign into the AzureAD PowerShell module
22$userPrincipalName = whoami -upn
23Connect-AzureAD -AccountId $userPrincipalName
24
25# Get the user information to update the signature
26$userObject = Get-AzureADUser -ObjectId $userPrincipalName
27
28# Create signatures folder if not exists
29if (-not (Test-Path "$($env:APPDATA)\Microsoft\Signatures")) {
30 $null = New-Item -Path "$($env:APPDATA)\Microsoft\Signatures" -ItemType Directory
31}
32
33#Location of signature, only doing html for time pressure... may revisit for txt/rtf.
34$LocalSignaturePath = (Get-Item env:appdata).Value + '\Microsoft\Signatures'
35$HtmlPath = $LocalSignaturePath + '\signature.htm'
36
37
38
39
40$CompanyLogo = "https://www.cyberdrain.com/wp-content/uploads/2021/04/Logo_shield_darkbg-2.png"
41$HeadingLine = "<title>Cyberdrain Signature</title><br>"
42
43$Main = "<table style="`"FONT-SIZE:" 8pt;="" color:="" gray;="" font-family:="" `'segoe="" ui`'="" `"=""> <tbody><tr><td><img src="" + $CompanyLogo + "" border="0"></td><td padding="0"><b>" + $userObject.GivenName + $userObject.Surname + " </b> " + $userObject.TelephoneNumber + " Email: " + $userObject.Mail + "</td></table><br><br>"
44
45# Put everything together and output the HTML file
46$SignatureHTML = $HeadingLine + $Main + $EndLine | Out-File $HtmlPath
47
48
49
50# Find Outlook Profiles in registry
51$CommonSettings = $False
52$Profiles = (Get-ChildItem HKCU:\Software\Microsoft\Office\16.0\Outlook\Profiles).PSChildName
53
54
55#would love to write proper and just change 16 to 14, but, time :( .... first 2016 signature...
56
57# This script can only deal with a single (default profile); more code needed to handle multiple profiles
58If ($Profiles -eq $Null -or $Profiles.Count -ne 1) {
59 Write-Host "Warning - Applying signature to all Outlook profiles"
60 $OutlookProfilePath = "HKCU:\Software\Microsoft\\Office\16.0\Common\MailSettings"
61 $CommonSettings = $True}
62Else { # Path to default profile is elsewhere in the registry
63 $OutLookProfilePath = "HKCU:\Software\Microsoft\Office\16.0\Outlook\Profiles\" + $Profiles.Trim() + "\9375CFF0413111d3B88A00104B2A6676\00000001" }
64
65
66
67# Update the registry settings where Outlook picks up its signature information
68If (Test-Path $TargetForSignatures) {
69 Get-Item -Path $OutlookProfilePath | New-Itemproperty -Name "New Signature" -value $SignatureName -Propertytype string -Force
70 Get-Item -Path $OutlookProfilePath | New-Itemproperty -Name "Reply-Forward Signature" -value $SignatureName -Propertytype string -Force }
71
72#now copying for 2013
73
74# This script can only deal with a single (default profile); more code needed to handle multiple profiles
75If ($Profiles -eq $Null -or $Profiles.Count -ne 1) {
76 Write-Host "Warning - Applying signature to all Outlook profiles"
77 $OutlookProfilePath = "HKCU:\Software\Microsoft\\Office\14.0\Common\MailSettings"
78 $CommonSettings = $True}
79Else { # Path to default profile is elsewhere in the registry
80 $OutLookProfilePath = "HKCU:\Software\Microsoft\Office\14.0\Outlook\Profiles\" + $Profiles.Trim() + "\9375CFF0413111d3B88A00104B2A6676\00000001" }
81
82
83
84# Update the registry settings where Outlook picks up its signature information
85If (Test-Path $TargetForSignatures) {
86 Get-Item -Path $OutlookProfilePath | New-Itemproperty -Name "New Signature" -value "CTF Signature" -Propertytype string -Force
87 Get-Item -Path $OutlookProfilePath | New-Itemproperty -Name "Reply-Forward Signature" -value "CTF Signature -Propertytype string -Force }
88
89#fingers crossed this is enough...
90
91Stop-Transcript