-
Notifications
You must be signed in to change notification settings - Fork 3
/
Get-ExODomains.ps1
40 lines (37 loc) · 2.19 KB
/
Get-ExODomains.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
# Similar to:
# https://github.com/Mike-Crowley/Public-Scripts/blob/main/Get-AlternateMailboxes.ps1
# "Get-TenantDomains" in this script: https://github.com/Gerenios/AADInternals/blob/ad071b736e2eb0f5f2b35df2920bb515b8c29a8c/AccessToken_utils.ps1
# Reported to Microsoft in 26Jul2018 who replied to say this is not a security issue, but a feature :)
function Get-ExODomains {
param (
[parameter(Mandatory = $true)][string]
$Domain
)
# https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/getfederationinformation-operation-soap
$body = @"
<soap:Envelope xmlns:exm="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:ext="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns:a="http://www.w3.org/2005/08/addressing"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<a:Action soap:mustUnderstand="1">http://schemas.microsoft.com/exchange/2010/Autodiscover/Autodiscover/GetFederationInformation</a:Action>
<a:To soap:mustUnderstand="1">https://autodiscover-s.outlook.com/autodiscover/autodiscover.svc</a:To>
</soap:Header>
<soap:Body>
<GetFederationInformationRequestMessage xmlns="http://schemas.microsoft.com/exchange/2010/Autodiscover">
<Request>
<Domain>$Domain</Domain>
</Request>
</GetFederationInformationRequestMessage>
</soap:Body>
</soap:Envelope>
"@
$headers = @{
"SOAPAction" = '"http://schemas.microsoft.com/exchange/2010/Autodiscover/Autodiscover/GetFederationInformation"'
}
$response = Invoke-RestMethod -Method Post -uri "https://autodiscover-s.outlook.com/autodiscover/autodiscover.svc" -Body $body -Headers $headers -UserAgent "AutodiscoverClient" -ContentType "text/xml; charset=utf-8"
$response.Envelope.body.GetFederationInformationResponseMessage.response.Domains.Domain | Sort-Object
}
Get-ExODomains -Domain example.com