/
Function-Test-ExchangeTools.ps1
76 lines (69 loc) · 2.62 KB
/
Function-Test-ExchangeTools.ps1
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
Function Test-ExchTools(){
<#
.SYNOPSIS
This small function will just check if you have Exchange tools installed or available on the
current PowerShell session.
.DESCRIPTION
The presence of Exchange tools are checked by trying to execute "Get-ExBanner", one of the basic Exchange
cmdlets that runs when the Exchange Management Shell is called.
Just use Test-ExchTools in your script to make the script exit if not launched from an Exchange
tools PowerShell session...
.EXAMPLE
Test-ExchTools
=> will exit the script/program si Exchange tools are not installed
#>
Try
{
#Get-command Get-ExBanner -ErrorAction Stop
Get-command Get-Mailbox -ErrorAction Stop
$ExchInstalledStatus = $true
$Message = "Exchange tools are present !"
Write-Host $Message -ForegroundColor Blue -BackgroundColor Red
}
Catch [System.SystemException]
{
$ExchInstalledStatus = $false
$Message = "Exchange Tools are not present ! This script/tool need these. Exiting..."
Write-Host $Message -ForegroundColor red -BackgroundColor Blue
Exit
}
Return $ExchInstalledStatus
}
Function Test-Exchange2016Tools {
$Exch2016InstalledStatus = $false
Try {
# Checking if Set-OutlookAnywhere comes with parameter "ExternalClientAuthenticationMethod", it's Exchange 2013/2016 tools
$GetHelpTest = get-help Set-OutlookAnywhere -parameter ExternalClientAuthenticationMethod -ErrorAction Stop
$Exch2016InstalledStatus = $true
$message = "Exchange 2016 tools detected"
Write-Host $message -ForegroundColor Blue -BackgroundColor Green
}
catch {
$Exch2016InstalledStatus = $false
$message = "Exchange 2016 tools not detected"
Write-Host $message -BackgroundColor Red -ForegroundColor Blue
}
Finally {
Write-Host "Done"
}
Return $Exch2016InstalledStatus
}
Function Test-Exchange2010Tools {
$Exch2010InstalledStatus = $false
Try {
# Checking if Set-OutlookAnywhere comes with parameter "ExternalClientAuthenticationMethod", it's Exchange 2013/2016 tools
$GetHelpTest = get-help Set-OutlookAnywhere -parameter ClientAuthenticationMethod -ErrorAction Stop
$Exch2010InstalledStatus = $true
$message = "Exchange 2010 tools detected"
Write-Host $message -ForegroundColor Blue -BackgroundColor green
}
catch {
$Exch2010InstalledStatus = $false
$message = "Exchange 2010 tools not detected"
Write-Host $message -BackgroundColor Red -ForegroundColor Blue
}
Finally {
Write-Host "Done"
}
Return $Exch2010InstalledStatus
}