-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest-IntuneConnectivity.ps1
More file actions
310 lines (282 loc) · 19 KB
/
Test-IntuneConnectivity.ps1
File metadata and controls
310 lines (282 loc) · 19 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<#
Script Name: Test-IntuneConnectivity.ps1
Author: Joymalya Basu Roy
DESCRIPTION
The script is created based on the Microsoft 365 IP Address and URL web service (https://aka.ms/ipurlws).
A REST API call is made to the Worldwide instance to obtain the latest endpoint URLs
for Service Area "MEM" and related "M365 Common" and then check connectivity to those endpoint URLs from the client.
Updated by James Vincent - March 2025 to include logging output.
PARAMETERS
n/a
PREREQUISITES
PS script execution policy: Bypass
PowerShell 3.0 or later
Does not require elevation
#>
$Timestamp = (Get-Date).toString("ddMMyyyy-HHmm")
$Logfile = "./Test-IntuneConnectivity-$Timestamp.log"
function WriteLog
{
Param ([string]$LogString)
$Stamp = (Get-Date).toString("dd/MM/yyyy HH:mm:ss")
$LogMessage = "$Stamp $LogString"
Add-content $LogFile -value $LogMessage -Encoding UTF8
}
Function Get-ProxySettings {
# Check Proxy settings
Write-Host "Checking winHTTP proxy settings..." -ForegroundColor Yellow
WriteLog "Checking winHTTP proxy settings..."
$ProxyServer = "NoProxy"
$winHTTP = netsh winhttp show proxy
$Proxy = $winHTTP | Select-String server
$ProxyServer = $Proxy.ToString().TrimStart("Proxy Server(s) : ")
if ($ProxyServer -eq "Direct access (no proxy server).") {
$ProxyServer = "NoProxy"
Write-Host "Access Type: DIRECT"
WriteLog "Access Type: DIRECT"
}
if ( ($ProxyServer -ne "NoProxy") -and (-not($ProxyServer.StartsWith("http://")))) {
Write-Host "Access Type: PROXY"
Write-Host "Proxy Server List: $($ProxyServer)"
WriteLog "Access Type: PROXY"
WriteLog "Proxy Server List: $($ProxyServer)"
$ProxyServer = "http://" + $ProxyServer
}
return $ProxyServer
}
Function Get-M365CommonEndpointList {
# Get up-to-date URLs
$endpointListM365 = (invoke-restmethod -Uri ("https://endpoints.office.com/endpoints/WorldWide?ServiceAreas=Common`&clientrequestid=" + ([GUID]::NewGuid()).Guid)) | Where-Object { $_.ServiceArea -eq "Common" -and $_.urls }
# Create categories to better understand what is being tested
[PsObject[]]$endpointListCategoriesM365 = @()
$endpointListCategoriesM365 += [PsObject]@{id = 56; category = 'M365 Common'; mandatory = $true }
$endpointListCategoriesM365 += [PsObject]@{id = 59; category = 'M365 Common'; mandatory = $true }
$endpointListCategoriesM365 += [PsObject]@{id = 78; category = 'M365 Common'; mandatory = $true }
$endpointListCategoriesM365 += [PsObject]@{id = 83; category = 'M365 Common'; mandatory = $true }
$endpointListCategoriesM365 += [PsObject]@{id = 84; category = 'M365 Common'; mandatory = $true }
$endpointListCategoriesM365 += [PsObject]@{id = 125; category = 'M365 Common'; mandatory = $true }
$endpointListCategoriesM365 += [PsObject]@{id = 156; category = 'M365 Common'; mandatory = $true }
# Create new output object and extract relevant test information (ID, category, URLs only)
[PsObject[]]$endpointRequestListM365 = @()
for ($i = 0; $i -lt $endpointListM365.Count; $i++) {
$endpointRequestListM365 += [PsObject]@{ id = $endpointListM365[$i].id; category = ($endpointListCategoriesM365 | Where-Object { $_.id -eq $endpointListM365[$i].id }).category; urls = $endpointListM365[$i].urls; mandatory = ($endpointListCategoriesM365 | Where-Object { $_.id -eq $endpointListM365[$i].id }).mandatory }
}
# Remove all *. from URL list (not useful)
for ($i = 0; $i -lt $endpointRequestListM365.Count; $i++) {
for ($j = 0; $j -lt $endpointRequestListM365[$i].urls.Count; $j++) {
$targetUrl = $endpointRequestListM365[$i].urls[$j].replace('*.', '')
$endpointRequestListM365[$i].urls[$j] = $targetURL
}
$endpointRequestListM365[$i].urls = $endpointRequestListM365[$i].urls | Sort-Object -Unique
}
return $endpointRequestListM365
}
Function Get-IntuneEndpointList {
# Get up-to-date URLs
$endpointList = (invoke-restmethod -Uri ("https://endpoints.office.com/endpoints/WorldWide?ServiceAreas=MEM`&clientrequestid=" + ([GUID]::NewGuid()).Guid)) | Where-Object { $_.ServiceArea -eq "MEM" -and $_.urls }
# Create categories to better understand what is being tested
[PsObject[]]$endpointListCategories = @()
$endpointListCategories += [PsObject]@{id = 163; category = 'Global'; mandatory = $true }
$endpointListCategories += [PsObject]@{id = 164; category = 'Delivery Optimization'; mandatory = $true }
$endpointListCategories += [PsObject]@{id = 165; category = 'NTP Sync'; mandatory = $true }
$endpointListCategories += [PsObject]@{id = 169; category = 'Windows Notifications & Store'; mandatory = $true }
$endpointListCategories += [PsObject]@{id = 170; category = 'Scripts & Win32 Apps'; mandatory = $true }
$endpointListCategories += [PsObject]@{id = 171; category = 'Push Notifications'; mandatory = $true }
$endpointListCategories += [PsObject]@{id = 172; category = 'Delivery Optimization'; mandatory = $true }
$endpointListCategories += [PsObject]@{id = 173; category = 'Autopilot Self-deploy'; mandatory = $true }
$endpointListCategories += [PsObject]@{id = 178; category = 'Apple Device Management'; mandatory = $false }
$endpointListCategories += [PsObject]@{id = 179; category = 'Android (AOSP) Device Management'; mandatory = $false }
$endpointListCategories += [PsObject]@{id = 181; category = 'Remote Help'; mandatory = $false }
$endpointListCategories += [PsObject]@{id = 182; category = 'Collect Diagnostics'; mandatory = $true }
$endpointListCategories += [PsObject]@{id = 186; category = 'Microsoft Azure attestation - Windows 11 only'; mandatory = $true }
$endpointListCategories += [PsObject]@{id = 187; category = 'Android Remote Help'; mandatory = $false }
$endpointListCategories += [PsObject]@{id = 188; category = 'Remote Help GCC Dependency'; mandatory = $false }
$endpointListCategories += [PsObject]@{id = 189; category = 'Feature Flighting'; mandatory = $false }
# Create new output object and extract relevant test information (ID, category, URLs only)
[PsObject[]]$endpointRequestList = @()
for ($i = 0; $i -lt $endpointList.Count; $i++) {
$endpointRequestList += [PsObject]@{ id = $endpointList[$i].id; category = ($endpointListCategories | Where-Object { $_.id -eq $endpointList[$i].id }).category; urls = $endpointList[$i].urls; mandatory = ($endpointListCategories | Where-Object { $_.id -eq $endpointList[$i].id }).mandatory }
}
# Remove all *. from URL list (not useful)
for ($i = 0; $i -lt $endpointRequestList.Count; $i++) {
for ($j = 0; $j -lt $endpointRequestList[$i].urls.Count; $j++) {
$targetUrl = $endpointRequestList[$i].urls[$j].replace('*.', '')
$endpointRequestList[$i].urls[$j] = $targetURL
}
$endpointRequestList[$i].urls = $endpointRequestList[$i].urls | Sort-Object -Unique
}
return $endpointRequestList
}
Function Test-DeviceIntuneConnectivity {
$ErrorActionPreference = 'SilentlyContinue'
$TestFailed = $false
$ProxyServer = Get-ProxySettings
$endpointListM365Common = Get-M365CommonEndpointList
$endpointListIntune = Get-IntuneEndpointList
$failedEndpointList = @{}
Write-Host "Starting Connectivity Check..." -ForegroundColor Yellow
WriteLog "Starting Connectivity Check..."
foreach ($endpoint in $endpointListM365Common)
{
if ($endpoint.mandatory -eq $true)
{
Write-Host "Checking Category: $($endpoint.category)" -ForegroundColor Yellow
WriteLog "Checking Category: $($endpoint.category)"
foreach ($url in $endpoint.urls) {
if ($ProxyServer -eq "NoProxy")
{
$TestResult = (Invoke-WebRequest -uri $url -UseBasicParsing).StatusCode
}
else
{
$TestResult = (Invoke-WebRequest -uri $url -UseBasicParsing -Proxy $ProxyServer).StatusCode
}
if ($TestResult -eq 200)
{
if (($url.StartsWith('approdimedata') -or ($url.StartsWith("intunemaape13") -or $url.StartsWith("intunemaape17") -or $url.StartsWith("intunemaape18") -or $url.StartsWith("intunemaape19")))) {
Write-Host "Connection to $($url).............. Succeeded (needed for Asia & Pacific tenants only)." -ForegroundColor Green
WriteLog "Connection to $($url).............. Succeeded (needed for Asia & Pacific tenants only)."
}
elseif (($url.StartsWith('euprodimedata') -or ($url.StartsWith("intunemaape7") -or $url.StartsWith("intunemaape8") -or $url.StartsWith("intunemaape9") -or $url.StartsWith("intunemaape10") -or $url.StartsWith("intunemaape11") -or $url.StartsWith("intunemaape12")))) {
Write-Host "Connection to $($url).............. Succeeded (needed for Europe tenants only)." -ForegroundColor Green
WriteLog "Connection to $($url).............. Succeeded (needed for Europe tenants only)."
}
elseif (($url.StartsWith('naprodimedata') -or ($url.StartsWith("intunemaape1") -or $url.StartsWith("intunemaape2") -or $url.StartsWith("intunemaape3") -or $url.StartsWith("intunemaape4") -or $url.StartsWith("intunemaape5") -or $url.StartsWith("intunemaape6")))) {
Write-Host "Connection to $($url).............. Succeeded (needed for North America tenants only)." -ForegroundColor Green
WriteLog "Connection to $($url).............. Succeeded (needed for North America tenants only)."
}
else {
Write-Host "Connection to $($url).............. Succeeded." -ForegroundColor Green
WriteLog "Connection to $($url).............. Succeeded."
}
}
else
{
$TestFailed = $true
if ($failedEndpointList.ContainsKey($endpoint.category)) {
$failedEndpointList[$endpoint.category] += $url
}
else {
$failedEndpointList.Add($endpoint.category, $url)
}
if (($url.StartsWith('approdimedata') -or ($url.StartsWith("intunemaape13") -or $url.StartsWith("intunemaape17") -or $url.StartsWith("intunemaape18") -or $url.StartsWith("intunemaape19")))) {
Write-Host "Connection to $($url).............. Failed (needed for Asia & Pacific tenants only)." -ForegroundColor Red
WriteLog "Connection to $($url).............. Failed (needed for Asia & Pacific tenants only)."
}
elseif (($url.StartsWith('euprodimedata') -or ($url.StartsWith("intunemaape7") -or $url.StartsWith("intunemaape8") -or $url.StartsWith("intunemaape9") -or $url.StartsWith("intunemaape10") -or $url.StartsWith("intunemaape11") -or $url.StartsWith("intunemaape12")))) {
Write-Host "Connection to $($url).............. Failed (needed for Europe tenants only)." -ForegroundColor Red
WriteLog "Connection to $($url).............. Failed (needed for Europe tenants only)."
}
elseif (($url.StartsWith('naprodimedata') -or ($url.StartsWith("intunemaape1") -or $url.StartsWith("intunemaape2") -or $url.StartsWith("intunemaape3") -or $url.StartsWith("intunemaape4") -or $url.StartsWith("intunemaape5") -or $url.StartsWith("intunemaape6")))) {
Write-Host "Connection to $($url).............. Failed (needed for North America tenants only)." -ForegroundColor Red
WriteLog "Connection to $($url).............. Failed (needed for North America tenants only)."
}
else {
Write-Host "Connection to $($url).............. Failed." -ForegroundColor Red
WriteLog "Connection to $($url).............. Failed."
}
}
}
}
else
{
#Write-Host "Skipping Category: ..." $endpoint.category -ForegroundColor Yellow
}
}
foreach ($endpoint in $endpointListIntune)
{
if ($endpoint.mandatory -eq $true)
{
Write-Host "Checking Category: $($endpoint.category)" -ForegroundColor Yellow
WriteLog "Checking Category: $($endpoint.category)"
foreach ($url in $endpoint.urls) {
if ($ProxyServer -eq "NoProxy") {
$TestResult = (Invoke-WebRequest -uri $url -UseBasicParsing).StatusCode
}
else {
$TestResult = (Invoke-WebRequest -uri $url -UseBasicParsing -Proxy $ProxyServer).StatusCode
}
if ($TestResult -eq 200) {
if (($url.StartsWith('approdimedata') -or ($url.StartsWith("intunemaape13") -or $url.StartsWith("intunemaape17") -or $url.StartsWith("intunemaape18") -or $url.StartsWith("intunemaape19")))) {
Write-Host "Connection to $($url).............. Succeeded (needed for Asia & Pacific tenants only)." -ForegroundColor Green
WriteLog "Connection to $($url).............. Succeeded (needed for Asia & Pacific tenants only)."
}
elseif (($url.StartsWith('euprodimedata') -or ($url.StartsWith("intunemaape7") -or $url.StartsWith("intunemaape8") -or $url.StartsWith("intunemaape9") -or $url.StartsWith("intunemaape10") -or $url.StartsWith("intunemaape11") -or $url.StartsWith("intunemaape12")))) {
Write-Host "Connection to $($url).............. Succeeded (needed for Europe tenants only)." -ForegroundColor Green
WriteLog "Connection to $($url).............. Succeeded (needed for Europe tenants only)."
}
elseif (($url.StartsWith('naprodimedata') -or ($url.StartsWith("intunemaape1") -or $url.StartsWith("intunemaape2") -or $url.StartsWith("intunemaape3") -or $url.StartsWith("intunemaape4") -or $url.StartsWith("intunemaape5") -or $url.StartsWith("intunemaape6")))) {
Write-Host "Connection to $($url).............. Succeeded (needed for North America tenants only)." -ForegroundColor Green
WriteLog "Connection to $($url).............. Succeeded (needed for North America tenants only)."
}
else {
Write-Host "Connection to $($url).............. Succeeded." -ForegroundColor Green
WriteLog "Connection to $($url).............. Succeeded."
}
}
else {
$TestFailed = $true
if ($failedEndpointList.ContainsKey($endpoint.category)) {
$failedEndpointList[$endpoint.category] += $url
}
else {
$failedEndpointList.Add($endpoint.category, $url)
}
if (($url.StartsWith('approdimedata') -or ($url.StartsWith("intunemaape13") -or $url.StartsWith("intunemaape17") -or $url.StartsWith("intunemaape18") -or $url.StartsWith("intunemaape19")))) {
Write-Host "Connection to $($url).............. Failed (needed for Asia & Pacific tenants only)." -ForegroundColor Red
WriteLog "Connection to $($url).............. Failed (needed for Asia & Pacific tenants only)."
}
elseif (($url.StartsWith('euprodimedata') -or ($url.StartsWith("intunemaape7") -or $url.StartsWith("intunemaape8") -or $url.StartsWith("intunemaape9") -or $url.StartsWith("intunemaape10") -or $url.StartsWith("intunemaape11") -or $url.StartsWith("intunemaape12")))) {
Write-Host "Connection to $($url).............. Failed (needed for Europe tenants only)." -ForegroundColor Red
WriteLog "Connection to $($url).............. Failed (needed for Europe tenants only)."
}
elseif (($url.StartsWith('naprodimedata') -or ($url.StartsWith("intunemaape1") -or $url.StartsWith("intunemaape2") -or $url.StartsWith("intunemaape3") -or $url.StartsWith("intunemaape4") -or $url.StartsWith("intunemaape5") -or $url.StartsWith("intunemaape6")))) {
Write-Host "Connection to $($url).............. Failed (needed for North America tenants only)." -ForegroundColor Red
WriteLog "Connection to $($url).............. Failed (needed for North America tenants only)."
}
else {
Write-Host "Connection to $($url).............. Failed." -ForegroundColor Red
WriteLog "Connection to $($url).............. Failed."
}
}
}
}
else
{
#Write-Host "Skipping Category: ..." $endpoint.category -ForegroundColor Yellow
}
}
# If the test failed
if ($TestFailed)
{
Write-Host "Test failed. Please check the following URLs:" -ForegroundColor Red
WriteLog "Test failed. Please check the following URLs:"
foreach ($failedEndpoint in $failedEndpointList.Keys) {
Write-Host $failedEndpoint -ForegroundColor Red
WriteLog $failedEndpoint
foreach ($failedUrl in $failedEndpointList[$failedEndpoint]) {
Write-Host $failedUrl -ForegroundColor Red
WriteLog $failedUrl
}
}
}
Write-Host "Test-DeviceIntuneConnectivity completed successfully." -ForegroundColor Green -BackgroundColor Black
WriteLog "Test-DeviceIntuneConnectivity completed successfully."
}
### Main ###
# Main function call
Test-DeviceIntuneConnectivity
# Get the current network config of the system and display
$NetworkConfiguration = @()
Get-NetIPConfiguration | ForEach-Object {
$NetworkConfiguration += New-Object PSObject -Property @{
InterfaceAlias = $_.InterfaceAlias
ProfileName = if($null -ne $_.NetProfile.Name){$_.NetProfile.Name}else{""}
IPv4Address = if($null -ne $_.IPv4Address){$_.IPv4Address}else{""}
IPv6Address = if($null -ne $_.IPv6Address){$_.IPv6Address}else{""}
IPv4DefaultGateway = if($null -ne $_.IPv4DefaultGateway){$_.IPv4DefaultGateway.NextHop}else{""}
IPv6DefaultGateway = if($null -ne $_.IPv6DefaultGateway){$_.IPv6DefaultGateway.NextHop}else{""}
DNSServer = if($null -ne $_.DNSServer){$_.DNSServer.ServerAddresses}else{""}
}
}
$NetworkConfiguration | Format-Table -AutoSize