-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGetAddInForAllUsers.ps1
More file actions
149 lines (137 loc) · 5.49 KB
/
GetAddInForAllUsers.ps1
File metadata and controls
149 lines (137 loc) · 5.49 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
# .SYNOPSIS
# Script to check what version of the Exclaimer Cloud Add-in is on each mailbox.
#
# .DESCRIPTION
# Will first check for required Module and prompt to install them if not present.
# It will then prompt the user to Sign in with Microsoft.
#
# .NOTES
# Email: helpdesk@exclaimer.com
# Created: 25th January 2024
# Updated: 7th October 2024
#
# .PRODUCTS
# Exclaimer Signature Management - Microsoft 365
#
# .REQUIREMENTS
# - Global Administrator access to the Microsoft Tenant
# - ExchangeOnlineManagement - https://learn.microsoft.com/en-us/powershell/exchange/exchange-online-powershell-v2?view=exchange-ps
#
# .VERSION
# 1.1.0
#
# .INSTRUCTIONS
# - Open PowerShell as Administrator
# - Run: set-executionpolicy unrestricted
# - Go to the directory where the Script is saved (i.e 'cd "C:\Users\ReplaceWithUserName\Downloads"')
# - Run the Script (i.e '.\GetAddInForAllUsers.ps1')
# Script Parameters
param(
[string]$OutputPath = "$PSScriptRoot\Exclaimer",
[string]$AddInID = "efc30400-2ac5-48b7-8c9b-c0fd5f266be2",
[switch]$VerboseLogging = $false
)
# Setting up logging if enabled
if ($VerboseLogging) {
$LogFile = "$OutputPath\ScriptLog.txt"
Write-Output "Verbose Logging Enabled: $LogFile"
Start-Transcript -Path $LogFile -Append -NoClobber
}
# Function to check and install required module
function Ensure-ModuleInstalled {
if (-not (Get-Module -ListAvailable -Name ExchangeOnlineManagement)) {
Write-Host "`nThe required 'ExchangeOnlineManagement' Module is NOT installed" -ForegroundColor Red
$installMsModule = Read-Host ("Do you want to install the required 'ExchangeOnlineManagement' Module? Y/n")
if ($installMsModule -eq "Y") {
try {
Install-Module ExchangeOnlineManagement -Scope CurrentUser -Force
Write-Host "`n'ExchangeOnlineManagement' Module 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
}
}
# Ensure output directory exists
function Ensure-DirectoryExists {
if (-not (Test-Path -Path $OutputPath)) {
try {
New-Item $OutputPath -ItemType Directory -Force | Out-Null
Write-Host "Created directory: $OutputPath" -ForegroundColor Green
} catch {
Write-Host "Failed to create directory: $OutputPath. Error: $_" -ForegroundColor Red
Exit
}
} else {
Write-Host "Output directory already exists: $OutputPath" -ForegroundColor Green
}
}
# Function to connect to Exchange Online
function Connect-ExchangeSession {
try {
#$session = Get-Module ExchangeOnlineManagement | Format-Table -Property Name,Version
$getsessions = Get-PSSession | Select-Object -Property State, Name
$session = (@($getsessions) -like '@{State=Opened; Name=ExchangeOnlineInternalSession*').Count -gt 0
if (-not $session) {
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 to gather mailbox add-in versions
function Get-MailboxAddInVersions {
$results = @()
try {
$mailboxes = Get-Mailbox -ResultSize Unlimited | Where-Object { $_.AccountDisabled -eq $false }
Write-Host "`nGathering information, please wait..........." -ForegroundColor Green
Write-Host "`nNote:" -ForegroundColor Red
Write-Host "Some mailboxes may not list an Add-in, you should try again after the specific mailbox has logged on to 'https://outlook.office.com/'...`n" -ForegroundColor Yellow
foreach ($mailbox in $mailboxes) {
$appIdentity = ($mailbox.UserPrincipalName -split "@")[0] + "\" + $AddInID
$appVersion = Get-App -Identity $appIdentity -ErrorAction SilentlyContinue
[array]$results += [pscustomobject]@{
Mailbox = $mailbox.DisplayName
AppVersion = $appVersion.AppVersion
Enabled = $appVersion.Enabled
Deployment_Method = $appVersion.Scope
}
}
# Output to CSV
$results | Export-Csv -Path "$OutputPath\GetAddInForAllUsers.csv" -NoTypeInformation
Write-Host "Output saved to $OutputPath\GetAddInForAllUsers.csv" -ForegroundColor Green
} catch {
Write-Host "Failed to retrieve mailbox information. Error: $_" -ForegroundColor Red
}
}
# Function to end the session
function End-ExchangeSession {
try {
Disconnect-ExchangeOnline -Confirm:$false
Write-Host "Disconnected from Exchange Online." -ForegroundColor Green
} catch {
Write-Host "Error disconnecting session. Error: $_" -ForegroundColor Red
}
}
#Open Ouput directory
function open-OutputDir {
Start "$OutputPath"
}
# Main Script Execution
Ensure-ModuleInstalled
Ensure-DirectoryExists
Connect-ExchangeSession
Get-MailboxAddInVersions
End-ExchangeSession
open-OutputDir
if ($VerboseLogging) { Stop-Transcript }