-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEnableAddInForAllUsers.ps1
More file actions
177 lines (151 loc) · 6.01 KB
/
Copy pathEnableAddInForAllUsers.ps1
File metadata and controls
177 lines (151 loc) · 6.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# .SYNOPSIS
# Script to enable the Exclaimer Cloud Add-in for all mailboxes where it is disabled.
#
# .DESCRIPTION
# Will first check for required Module and prompt to install if not present.
# It will then connect to Exchange Online and check the add-in status for every
# active mailbox. Any mailbox where the add-in is present but disabled will have
# it re-enabled. Results are exported to CSV.
#
# .NOTES
# Created: 2026
#
# .PRODUCTS
# Exclaimer Signature Management - Microsoft 365
#
# .REQUIREMENTS
# - Global Administrator access to the Microsoft Tenant
# - ExchangeOnlineManagement module
#
# .VERSION
# 1.0.0
param(
[string]$AddInID = "efc30400-2ac5-48b7-8c9b-c0fd5f266be2",
[switch]$VerboseLogging = $false
)
# Preferred output path (Downloads -> fallback C:\Temp)
$OutputPath = [System.IO.Path]::Combine([Environment]::GetFolderPath('UserProfile'), 'Downloads')
if (-not (Test-Path -Path $OutputPath)) {
$OutputPath = "C:\Temp"
if (-not (Test-Path -Path $OutputPath)) {
New-Item -Path $OutputPath -ItemType Directory -Force | Out-Null
}
}
# File naming
$TimeStamp = Get-Date -Format 'yyyyMMdd_HHmmss'
$CsvFilePath = Join-Path $OutputPath "EnableAddInForAllUsers_$TimeStamp.csv"
$TranscriptFile = Join-Path $OutputPath "Transcript_EnableAddIn_$TimeStamp.txt"
if ($VerboseLogging) {
Write-Output "Verbose Logging Enabled: $TranscriptFile"
Start-Transcript -Path $TranscriptFile -Append -NoClobber
}
function Ensure_ModuleInstalled {
if (-not (Get-Module -ListAvailable -Name ExchangeOnlineManagement)) {
Write-Host "`nThe required 'ExchangeOnlineManagement' Module is NOT installed" -ForegroundColor Red
$install = Read-Host "Do you want to install it? Y/n"
if ($install -eq "Y") {
try {
Install-Module ExchangeOnlineManagement -Scope CurrentUser -Force
Write-Host "'ExchangeOnlineManagement' installed successfully." -ForegroundColor Green
} catch {
Write-Host "Failed to install module. Error: $_" -ForegroundColor Red
Exit
}
} else {
Write-Host "Cannot continue without 'ExchangeOnlineManagement'. Exiting..." -ForegroundColor Red
Exit
}
} else {
Write-Host "`nThe 'ExchangeOnlineManagement' Module is already installed" -ForegroundColor Green
}
}
function Connect_ExchangeSession {
try {
$sessions = Get-PSSession | Select-Object -Property State, Name
$active = (@($sessions) -like '@{State=Opened; Name=ExchangeOnlineInternalSession*').Count -gt 0
if (-not $active) {
Write-Host "Starting a new session..." -ForegroundColor Green
Connect-ExchangeOnline
} else {
Write-Host "Exchange Online session is already active." -ForegroundColor Green
}
} catch {
Write-Host "Failed to connect to Exchange Online. Error: $_" -ForegroundColor Red
Exit
}
}
function Enable_AddInForAllMailboxes {
$results = @()
try {
$mailboxes = Get-Mailbox -ResultSize Unlimited |
Where-Object { $_.AccountDisabled -eq $false }
$total = $mailboxes.Count
$counter = 0
Write-Host "`nProcessing $total mailboxes..." -ForegroundColor Green
foreach ($mbx in $mailboxes) {
$counter++
Write-Progress -Activity "Checking and enabling add-in" `
-Status "$counter of $total : $($mbx.UserPrincipalName)" `
-PercentComplete (($counter / $total) * 100)
$appIdentity = "$($mbx.UserPrincipalName)\$AddInID"
$status = $null
$action = $null
$errorMsg = $null
try {
$app = Get-App -Identity $appIdentity -ErrorAction Stop
$status = $app.Enabled
if ($app.Enabled -eq $false) {
Enable-App -Identity $appIdentity -ErrorAction Stop
$action = "Enabled"
Write-Host "Re-enabled: $($mbx.UserPrincipalName)" -ForegroundColor Yellow
} else {
$action = "AlreadyEnabled"
}
} catch {
$errorMsg = $_.Exception.Message
$action = "Error"
}
$results += [pscustomobject]@{
Mailbox = $mbx.DisplayName
UPN = $mbx.UserPrincipalName
WasEnabled = $status
Action = $action
Error = $errorMsg
}
}
Write-Progress -Activity "Checking and enabling add-in" -Completed
$results | Export-Csv -Path $CsvFilePath -NoTypeInformation
Write-Host "`nOutput saved to: $CsvFilePath" -ForegroundColor Green
# Summary
$alreadyEnabled = ($results | Where-Object { $_.Action -eq "AlreadyEnabled" }).Count
$reEnabled = ($results | Where-Object { $_.Action -eq "Enabled" }).Count
$errors = ($results | Where-Object { $_.Action -eq "Error" }).Count
Write-Host "`n--- Summary ---" -ForegroundColor Cyan
Write-Host "Total mailboxes : $total"
Write-Host "Already enabled : $alreadyEnabled" -ForegroundColor Green
Write-Host "Re-enabled now : $reEnabled" -ForegroundColor Yellow
Write-Host "Errors / absent : $errors" -ForegroundColor Red
} catch {
Write-Host "Fatal error retrieving mailbox list. Error: $_" -ForegroundColor Red
}
}
function End_ExchangeSession {
try {
Disconnect-ExchangeOnline -Confirm:$false
Write-Host "Disconnected from Exchange Online." -ForegroundColor Green
} catch {
Write-Host "Error disconnecting. Error: $_" -ForegroundColor Red
}
}
function Open_OutputDir {
Start-Process $OutputPath
}
# Main execution
Ensure_ModuleInstalled
Connect_ExchangeSession
Enable_AddInForAllMailboxes
End_ExchangeSession
Open_OutputDir
if ($VerboseLogging) {
Stop-Transcript
}