Last active
August 13, 2019 14:58
-
-
Save poiriersimon/02b9efa607f0cb77d78805a7ac4077d7 to your computer and use it in GitHub Desktop.
Test Exchange Online URL connectivity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Based on : https://docs.microsoft.com/en-us/office365/enterprise/office-365-ip-web-service | |
# webservice root URL | |
$ws = "https://endpoints.office.com" | |
$clientRequestId = [GUID]::NewGuid().Guid | |
# invoke endpoints method to get the new data | |
$endpointSets = Invoke-RestMethod -Uri ($ws + "/endpoints/Worldwide?clientRequestId=" + $clientRequestId) | |
# filter results for Allow and Optimize endpoints, and transform these into custom objects with port and category | |
$flatUrls = $endpointSets | where{$_.serviceArea -eq "Exchange" -or $_.serviceArea -eq "Common"}| ForEach-Object { | |
$endpointSet = $_ | |
$urls = $(if ($endpointSet.urls.Count -gt 0) { $endpointSet.urls } else { @() }) | |
$urlCustomObjects = @() | |
if ($endpointSet.category -in ("Allow", "Optimize")) { | |
$urlCustomObjects = $urls | ForEach-Object { | |
[PSCustomObject]@{ | |
category = $endpointSet.category; | |
url = $_; | |
tcpPorts = $endpointSet.tcpPorts; | |
udpPorts = $endpointSet.udpPorts; | |
} | |
} | |
} | |
$urlCustomObjects | |
} | |
$URLConnectivityResult = ForEach($URL in $flatUrls){ | |
if($url.tcpPorts -ne $NULL){ | |
foreach($TcpPort in $url.tcpPorts.split(",")){ | |
$tResult = test-netconnection $($url.url.TrimStart("*.")) -port $TcpPort | |
[PSCustomObject]@{ | |
category = $Url.category; | |
url = $URL.url; | |
Port = $TcpPort; | |
Success = $tResult.TcpTestSucceeded; | |
} | |
} | |
} | |
} | |
$URLConnectivityResult |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment