forked from timmcmic/DLConversionV2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-mailOnMicrosoftComDomain.ps1
72 lines (55 loc) · 2.51 KB
/
get-mailOnMicrosoftComDomain.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
<#
.SYNOPSIS
This function determines the hybrid mail.onmicrosoft.com domain name.
This function is required to support additions of onmicrosoft.com domain names which can be used as addresses but not for routing.
.DESCRIPTION
This function determines the hybrid mail.onmicrosoft.com domain name.
.EXAMPLE
Get-MailOnMicrosoftComDomain
#>
Function Get-MailOnMicrosoftComDomain
{
[cmdletbinding()]
#Define variables that will be utilzed in the function.
[string]$functionDomainName = ""
[array]$functionAcceptedDomains = @()
[string]$functionDomainString0 = "mail.onmicrosoft.com"
[string]$functionDomainString1 = "microsoftonline.com"
#Initiate the test.
Out-LogFile -string "********************************************************************************"
Out-LogFile -string "BEGIN Get-MailOnMicrosoftComDomain"
Out-LogFile -string "********************************************************************************"
try{
$functionAcceptedDomains = get-o365acceptedDomain -errorAction STOP
}
catch{
out-logfile -string $_
out-logfile -string "Error obtaining accepted domains." -isError:$TRUE
}
foreach ($domain in $functionAcceptedDomains)
{
out-logfile -string ("Testing Domain: "+$domain.domainName)
if ($domain.domainName.contains($functionDomainString0))
{
out-logfile -string ("Mail.onmicrosoft.com domain name found: "+$domain.domainName)
$functionDomainName = $domain.domainName
}
elseif ($domain.domainName.contains($functionDomainString1))
{
out-logfile -string ("Legacy microsoft online domain name found: "+$domain.domainName)
$functionDomainName = $domain.domainName
}
else
{
out-logfile -string ("Domain is not mail.onmicrosoft.com: "+$domain.domainName)
}
}
if ($functionDomainName -eq "")
{
out-logfile -string "No viable mail routing address was found."
out-logfile -string "Contact support or post an issue on GITHUB." -isError:$true
}
Out-LogFile -string "END Get-MailOnMicrosoftComDomain"
Out-LogFile -string "********************************************************************************"
return $functionDomainName
}