Repository navigation
Expand file tree
/
Copy pathGet-AlternateMailboxes_BasicAuth.ps1
More file actions
79 lines (67 loc) · 3.17 KB
/
Copy pathGet-AlternateMailboxes_BasicAuth.ps1
File metadata and controls
79 lines (67 loc) · 3.17 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
<#
.SYNOPSIS
Queries the AlternateMailboxes node from a user's Exchange AutoDiscover response (Basic Auth).
.DESCRIPTION
Queries the AlternateMailboxes node within a user's AutoDiscover response using Basic Auth.
For Modern Auth support, see Get-AlternateMailboxes.ps1.
.PARAMETER SMTPAddress
The SMTP email address of the user to query.
.PARAMETER Credential
A PSCredential object for Basic Auth against Exchange AutoDiscover.
.EXAMPLE
Get-AlternateMailboxes -SMTPAddress user@example.com -Credential (Get-Credential)
.NOTES
Author: Mike Crowley
https://mikecrowley.us
.LINK
https://mikecrowley.us/2017/12/08/querying-msexchdelegatelistlink-in-exchange-online-with-powershell/
#>
Function Get-AlternateMailboxes {
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$SMTPAddress,
[Parameter(Mandatory = $true)]
[pscredential]$Credential
)
$AutoDiscoverRequest = @"
<soap:Envelope xmlns:a="http://schemas.microsoft.com/exchange/2010/Autodiscover"
xmlns:wsa="http://www.w3.org/2005/08/addressing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<a:RequestedServerVersion>Exchange2013</a:RequestedServerVersion>
<wsa:Action>http://schemas.microsoft.com/exchange/2010/Autodiscover/Autodiscover/GetUserSettings</wsa:Action>
<wsa:To>https://autodiscover.exchange.microsoft.com/autodiscover/autodiscover.svc</wsa:To>
</soap:Header>
<soap:Body>
<a:GetUserSettingsRequestMessage xmlns:a="http://schemas.microsoft.com/exchange/2010/Autodiscover">
<a:Request>
<a:Users>
<a:User>
<a:Mailbox>$SMTPAddress</a:Mailbox>
</a:User>
</a:Users>
<a:RequestedSettings>
<a:Setting>UserDisplayName</a:Setting>
<a:Setting>UserDN</a:Setting>
<a:Setting>UserDeploymentId</a:Setting>
<a:Setting>MailboxDN</a:Setting>
<a:Setting>AlternateMailboxes</a:Setting>
</a:RequestedSettings>
</a:Request>
</a:GetUserSettingsRequestMessage>
</soap:Body>
</soap:Envelope>
"@
#Other attributes available here: https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.autodiscover.usersettingname(v=exchg.80).aspx
$Headers = @{
'X-AnchorMailbox' = $Credential.UserName
}
$WebResponse = Invoke-WebRequest https://autodiscover-s.outlook.com/autodiscover/autodiscover.svc -Credential $Credential -Method Post -Body $AutoDiscoverRequest -ContentType 'text/xml; charset=utf-8' -Headers $Headers
[System.Xml.XmlDocument]$XMLResponse = $WebResponse.Content
$RequestedSettings = $XMLResponse.Envelope.Body.GetUserSettingsResponseMessage.Response.UserResponses.UserResponse.UserSettings.UserSetting
return $RequestedSettings.AlternateMailboxes.AlternateMailbox
}
# Get-AlternateMailboxes -SMTPAddress user@example.com -Credential (Get-Credential)