Skip to content

Instantly share code, notes, and snippets.

@Apoc70
Created January 9, 2026 13:50
Show Gist options
  • Select an option

  • Save Apoc70/7ba2e2bf7b5d9bcd90bd128cf9aad652 to your computer and use it in GitHub Desktop.

Select an option

Save Apoc70/7ba2e2bf7b5d9bcd90bd128cf9aad652 to your computer and use it in GitHub Desktop.
Helper script to query Exchange AutoDiscover v2 endpoints
param(
[Parameter(Mandatory = $true)]
[string]$Email, # Email address to query AutoD for
[Parameter(Mandatory = $true)]
[ValidateSet('EWS', 'ActiveSync', 'Rest')] # Protocol to use
[string]$Protocol,
[string]$Server = 'outlook.office365.com' # Default to Office 365, use another server if needed
)
$uri = "https://$Server/autodiscover/autodiscover.json?Email=$Email&Protocol=$Protocol"
try {
$result = Invoke-RestMethod -Uri $uri -Headers @{ 'Accept' = 'application/json' } -TimeoutSec 30
Write-Host "Queried: $uri" -ForegroundColor Cyan
$result
}
catch {
Write-Warning "Failed to query AutoD for $Email using $Protocol. Error: $_"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment