Skip to content

Instantly share code, notes, and snippets.

@bill-long
Created October 4, 2022 20:23
Show Gist options
  • Save bill-long/e57d70355a5eb680d8bfaf68d11b6869 to your computer and use it in GitHub Desktop.
Save bill-long/e57d70355a5eb680d8bfaf68d11b6869 to your computer and use it in GitHub Desktop.
Super simple AutoDiscover test. Does not attempt to encapsulate all of Outlook's logic.
[CmdletBinding()]
param (
[Parameter()]
[string]
$HostName,
[Parameter()]
[string]
$EmailAddress
)
$body = '<?xml version="1.0" encoding="utf-8"?><Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006"><Request><EMailAddress>' + $EmailAddress + '</EMailAddress><AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema></Request></Autodiscover>'
$response = Invoke-WebRequest "https://$HostName/autodiscover/autodiscover.xml" -Method POST -ContentType "text/xml" -Body $body -UseDefaultCredentials
if ($response.StatusCode -eq 200) {
$response.Content
} else {
$response
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment