-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckMEMEndpoints.ps1
More file actions
659 lines (550 loc) · 24 KB
/
Copy pathCheckMEMEndpoints.ps1
File metadata and controls
659 lines (550 loc) · 24 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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
[CmdletBinding()]
param(
[Parameter(HelpMessage="Skip ping latency tests to speed up execution")]
[switch]$SkipPing,
[Parameter(HelpMessage="Skip download speed tests to speed up execution")]
[switch]$SkipSpeed,
[Parameter(HelpMessage="Run in quiet mode with minimal output")]
[switch]$Quiet,
[Parameter(HelpMessage="Generate detailed log file")]
[string]$LogFile = "MEM-Endpoints-Test-$(Get-Date -Format 'yyyyMMdd-HHmmss').log",
[Parameter(HelpMessage="Test timeout in seconds")]
[int]$TimeoutSeconds = 10,
[Parameter(HelpMessage="Use legacy Office endpoint API (best-effort only for MEM/Intune)")]
[switch]$UseLegacyOfficeEndpointApi
)
<#
.SYNOPSIS
Microsoft Endpoint Manager (MEM) Connectivity and Performance Tester
.DESCRIPTION
This script tests Microsoft Endpoint Manager (MEM/Intune) connectivity against a maintained baseline
endpoint list. Optionally, it can merge data from the legacy Office endpoint API in best-effort mode.
It provides detailed connectivity, latency, and response-time measurements with comprehensive logging.
The script performs the following operations:
1. Loads maintained MEM/Intune baseline URLs and optionally merges legacy API data
2. Tests TCP connectivity to all endpoints on port 443 (HTTPS)
3. Measures ping latency for performance analysis (optional)
4. Tests download speed/response time to evaluate network quality (optional)
5. Generates detailed log files for comparison and troubleshooting
6. Provides color-coded output for easy identification of connectivity issues
7. Returns appropriate exit codes for automation scenarios
The log file contains:
- Test execution timestamp and duration
- Complete list of tested IPs and URLs with results
- Performance statistics (latency, speed)
- Connectivity summary for easy comparison
- Detailed error information for failed connections
.PARAMETER SkipPing
Skips ping latency testing to reduce execution time. Only basic connectivity will be tested.
.PARAMETER SkipSpeed
Skips download speed/response time testing to reduce execution time.
.PARAMETER Quiet
Runs in quiet mode with minimal console output. Results are still logged.
.PARAMETER LogFile
Specifies the path for the log file. If not provided, creates a timestamped log file in current directory.
.PARAMETER TimeoutSeconds
Timeout in seconds for network tests. Default is 10 seconds.
.PARAMETER UseLegacyOfficeEndpointApi
Uses the legacy Office endpoint API as a best-effort supplement for MEM data.
.NOTES
File Name : CheckMEMEndpoints.ps1
Author : Created based on requirements
Version : 1.1
Creation Date : October 16, 2025
Requirements : PowerShell 5.1 or higher, Internet connectivity
Network : HTTPS (443) access to Microsoft endpoints, ICMP for ping tests
Permissions : No elevated privileges required
.EXAMPLE
.\CheckMEMEndpoints.ps1
Runs complete connectivity test with ping and speed tests, creates timestamped log file.
.EXAMPLE
.\CheckMEMEndpoints.ps1 -SkipPing -SkipSpeed -Quiet
Runs basic connectivity test only in quiet mode with logging.
.EXAMPLE
.\CheckMEMEndpoints.ps1 -LogFile "C:\Logs\MEM-Test.log"
Runs complete test and saves results to specified log file.
.EXAMPLE
.\CheckMEMEndpoints.ps1 -UseLegacyOfficeEndpointApi
Runs baseline checks and additionally merges legacy Office endpoint API data.
#>
# Function to write to log file with timestamp
function Write-Log {
param(
[string]$Message,
[string]$Level = "INFO"
)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$logEntry = "[$timestamp] [$Level] $Message"
# Write to log file
Add-Content -Path $script:LogFile -Value $logEntry -Encoding UTF8
# Also write to console if not quiet
if (-not $Quiet) {
switch ($Level) {
"ERROR" { Write-Host $logEntry -ForegroundColor Red }
"WARN" { Write-Host $logEntry -ForegroundColor Yellow }
"SUCCESS" { Write-Host $logEntry -ForegroundColor Green }
"INFO" { Write-Host $logEntry -ForegroundColor Cyan }
default { Write-Host $logEntry }
}
}
}
# Function to test ping latency
function Test-PingLatency {
param (
[string]$HostName,
[int]$Count = 4,
[int]$TimeoutSeconds = 5
)
try {
$pingResults = Test-Connection -ComputerName $HostName -Count $Count -TimeoutSeconds $TimeoutSeconds -ErrorAction Stop
$avgLatency = ($pingResults | Measure-Object ResponseTime -Average).Average
return [math]::Round($avgLatency, 2)
}
catch {
return $null
}
}
# Function to test HTTPS response time
function Test-DownloadSpeed {
param (
[string]$Url,
[int]$TimeoutSeconds = 10
)
try {
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
# Try different approaches for speed testing
$webClient = New-Object System.Net.WebClient
$webClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36")
try {
# First try favicon.ico
$testUrl = $Url.TrimEnd('/') + "/favicon.ico"
$data = $webClient.DownloadData($testUrl)
$stopwatch.Stop()
if ($stopwatch.ElapsedMilliseconds -gt 0 -and $data.Length -gt 0) {
return [math]::Round($stopwatch.ElapsedMilliseconds, 2)
}
}
catch {
# If favicon doesn't work, try HEAD request for response time
try {
$request = [System.Net.WebRequest]::Create($Url)
$request.Method = "HEAD"
$request.Timeout = $TimeoutSeconds * 1000
$stopwatch.Restart()
$response = $request.GetResponse()
$stopwatch.Stop()
$response.Close()
return [math]::Round($stopwatch.ElapsedMilliseconds, 2)
}
catch {
# Last resort: try GET request with timeout
$request = [System.Net.WebRequest]::Create($Url)
$request.Method = "GET"
$request.Timeout = $TimeoutSeconds * 1000
$stopwatch.Restart()
$response = $request.GetResponse()
$stopwatch.Stop()
$response.Close()
return [math]::Round($stopwatch.ElapsedMilliseconds, 2)
}
}
finally {
$webClient.Dispose()
}
}
catch {
return $null
}
return $null
}
# Function to get MEM IPs
function Get-MEMIPs {
if ($UseLegacyOfficeEndpointApi) {
Write-Log "Retrieving MEM IP addresses from legacy Office endpoint API (best-effort)..." "WARN"
try {
$uri = "https://endpoints.office.com/endpoints/WorldWide?ServiceAreas=MEM&clientrequestid=" + ([GUID]::NewGuid()).Guid
$response = Invoke-RestMethod -Uri $uri -ErrorAction Stop
$ips = $response | Where-Object {$_.ServiceArea -eq "MEM" -and $_.ips} | Select-Object -Unique -ExpandProperty ips
Write-Log "Retrieved $($ips.Count) unique IP addresses/ranges from legacy API" "SUCCESS"
return $ips
}
catch {
Write-Log "Error retrieving MEM IPs from legacy API: $($_.Exception.Message)" "ERROR"
return @()
}
}
Write-Log "Skipping IP-range API retrieval by default. Use URL baseline checks for MEM/Intune." "WARN"
return @()
}
# Function to get MEM URLs from maintained baseline (and optional legacy API merge)
function Get-MEMURLs {
$baselineUrls = @(
'https://manage.microsoft.com',
'https://*.manage.microsoft.com',
'https://*.dm.microsoft.com',
'https://endpoint.microsoft.com',
'https://graph.microsoft.com',
'https://login.microsoftonline.com',
'https://device.login.microsoftonline.com',
'https://enterpriseregistration.windows.net',
'https://certauth.enterpriseregistration.windows.net',
'https://*.do.dsp.mp.microsoft.com',
'https://*.dl.delivery.mp.microsoft.com',
'https://*.delivery.mp.microsoft.com',
'https://*.events.data.microsoft.com',
'https://*.notify.windows.com',
'https://*.wns.windows.com',
'https://displaycatalog.mp.microsoft.com',
'https://licensing.mp.microsoft.com',
'https://purchase.md.mp.microsoft.com',
'https://mmdcustomer.microsoft.com',
'https://mmdls.microsoft.com',
'https://devicelistenerprod.microsoft.com',
'https://login.windows.net',
'https://device.autopatch.microsoft.com',
'https://services.autopatch.microsoft.com',
'https://payloadprod*.blob.core.windows.net',
'https://*.webpubsub.azure.com'
)
Write-Log "Loaded $($baselineUrls.Count) baseline MEM/Intune URLs" "SUCCESS"
$urls = $baselineUrls
if ($UseLegacyOfficeEndpointApi) {
Write-Log "Merging legacy Office endpoint API URLs (best-effort)..." "WARN"
try {
$uri = "https://endpoints.office.com/endpoints/WorldWide?ServiceAreas=MEM&clientrequestid=" + ([GUID]::NewGuid()).Guid
$response = Invoke-RestMethod -Uri $uri -ErrorAction Stop
$legacyUrls = $response | Where-Object {$_.ServiceArea -eq "MEM" -and $_.urls} | Select-Object -Unique -ExpandProperty urls
$urls += $legacyUrls
Write-Log "Merged $($legacyUrls.Count) URLs from legacy API" "SUCCESS"
}
catch {
Write-Log "Legacy API URL merge failed: $($_.Exception.Message)" "WARN"
}
}
return $urls | Sort-Object -Unique
}
# Function to test IP connectivity (convert CIDR to testable IPs)
function Test-IPConnectivity {
param(
[string]$IPRange,
[int]$Port = 443
)
# Handle CIDR notation - for testing purposes, we'll test the network address
if ($IPRange -match '^(\d+\.\d+\.\d+\.\d+)/(\d+)$') {
$ip = $matches[1]
$prefixLength = [int]$matches[2]
# For /32, test the exact IP. For others, test the network address
if ($prefixLength -eq 32) {
$testIP = $ip
} else {
$testIP = $ip
}
} elseif ($IPRange -match '^\d+\.\d+\.\d+\.\d+$') {
# Single IP address
$testIP = $IPRange
} else {
Write-Log "Unsupported IP format: $IPRange" "WARN"
return $null
}
try {
$result = Test-NetConnection -ComputerName $testIP -Port $Port -WarningAction SilentlyContinue
return $result
}
catch {
Write-Log "Error testing IP $testIP : $($_.Exception.Message)" "ERROR"
return $null
}
}
# Function to test URL connectivity
function Test-URLConnectivity {
param(
[string]$Url,
[int]$Port = 443
)
# Extract hostname from URL
$hostname = ($Url -replace 'https?://', '').Split('/')[0]
# Handle wildcard URLs with deterministic replacement for connectivity checks
if ($hostname -like '*`**') {
$hostname = $hostname -replace '^\*\.', 'www.'
$hostname = $hostname -replace '\*', 'prod'
}
try {
$result = Test-NetConnection -ComputerName $hostname -Port $Port -WarningAction SilentlyContinue
return $result
}
catch {
Write-Log "Error testing URL $hostname : $($_.Exception.Message)" "ERROR"
return $null
}
}
# Main script execution
$script:startTime = Get-Date
$script:LogFile = $LogFile
# Initialize log file
Write-Log "=== Microsoft Endpoint Manager (MEM) Connectivity Test ===" "INFO"
Write-Log "Script Version: 1.1" "INFO"
Write-Log "Test Configuration:" "INFO"
Write-Log " - Ping Tests: $(if($SkipPing){'Disabled'}else{'Enabled'})" "INFO"
Write-Log " - Speed Tests: $(if($SkipSpeed){'Disabled'}else{'Enabled'})" "INFO"
Write-Log " - Timeout: $TimeoutSeconds seconds" "INFO"
Write-Log " - Quiet Mode: $(if($Quiet){'Enabled'}else{'Disabled'})" "INFO"
Write-Log "" "INFO"
if (-not $Quiet) {
Write-Host "`n🌐 MICROSOFT ENDPOINT MANAGER (MEM) CONNECTIVITY TESTER" -ForegroundColor Cyan
Write-Host "="*70 -ForegroundColor DarkCyan
Write-Host "Loading MEM/Intune endpoint baseline..." -ForegroundColor Yellow
}
# Get MEM IPs and URLs from baseline (optional legacy API merge)
$memIPs = Get-MEMIPs
$memURLs = Get-MEMURLs
if ($memIPs.Count -eq 0 -and $memURLs.Count -eq 0) {
Write-Log "No MEM endpoints retrieved from Microsoft API. Exiting." "ERROR"
exit 1
}
Write-Log "Starting connectivity tests..." "INFO"
Write-Log "IPs to test: $($memIPs.Count)" "INFO"
Write-Log "URLs to test: $($memURLs.Count)" "INFO"
$results = @()
$totalEndpoints = $memIPs.Count + $memURLs.Count
$currentEndpoint = 0
if (-not $Quiet) {
Write-Host "`n🔍 Testing $totalEndpoints MEM endpoints (IPs: $($memIPs.Count), URLs: $($memURLs.Count))" -ForegroundColor Cyan
Write-Host "This may take several minutes..." -ForegroundColor Yellow
Write-Host ""
}
# Test IP addresses
foreach ($ip in $memIPs) {
$currentEndpoint++
Write-Progress -Activity "Testing MEM Endpoints" -Status "Testing IP $ip ($currentEndpoint of $totalEndpoints)" -PercentComplete (($currentEndpoint / $totalEndpoints) * 100)
Write-Log "Testing IP: $ip" "INFO"
$connectResult = Test-IPConnectivity -IPRange $ip
if ($connectResult -and $connectResult.TcpTestSucceeded) {
$status = 'OK'
$ipAddress = $connectResult.RemoteAddress
Write-Log "IP $ip - Connection successful (Resolved to: $ipAddress)" "SUCCESS"
# Test ping if enabled
$pingLatency = $null
if (-not $SkipPing -and $ipAddress) {
Write-Log "Testing ping to $ipAddress..." "INFO"
$pingLatency = Test-PingLatency -HostName $ipAddress -TimeoutSeconds $TimeoutSeconds
if ($pingLatency) {
Write-Log "Ping to $ipAddress : $pingLatency ms" "SUCCESS"
} else {
Write-Log "Ping to $ipAddress failed" "WARN"
}
}
# Test speed if enabled
$downloadSpeed = $null
if (-not $SkipSpeed) {
Write-Log "Testing response time to https://$ipAddress..." "INFO"
$downloadSpeed = Test-DownloadSpeed -Url "https://$ipAddress" -TimeoutSeconds $TimeoutSeconds
if ($downloadSpeed) {
Write-Log "Response time to $ipAddress : $downloadSpeed ms" "SUCCESS"
} else {
Write-Log "Speed test to $ipAddress failed" "WARN"
}
}
} else {
$status = 'FAILED'
$ipAddress = $null
Write-Log "IP $ip - Connection FAILED" "ERROR"
}
$results += [PSCustomObject]@{
Type = 'IP'
Endpoint = $ip
Status = $status
ResolvedIP = $ipAddress
PingLatency_ms = $pingLatency
DownloadSpeed_Kbps = $downloadSpeed
}
}
# Test URLs
foreach ($url in $memURLs) {
$currentEndpoint++
$hostname = ($url -replace 'https?://', '').Split('/')[0]
# Handle wildcards for display
$displayUrl = $url
if ($url.StartsWith('*.')) {
$displayUrl = $url -replace '^\*\.', 'www.'
}
Write-Progress -Activity "Testing MEM Endpoints" -Status "Testing URL $displayUrl ($currentEndpoint of $totalEndpoints)" -PercentComplete (($currentEndpoint / $totalEndpoints) * 100)
Write-Log "Testing URL: $url" "INFO"
$connectResult = Test-URLConnectivity -Url $url
if ($connectResult -and $connectResult.TcpTestSucceeded) {
$status = 'OK'
$ipAddress = $connectResult.RemoteAddress
Write-Log "URL $url - Connection successful (Resolved to: $ipAddress)" "SUCCESS"
# Test ping if enabled
$pingLatency = $null
if (-not $SkipPing -and $ipAddress) {
Write-Log "Testing ping to $hostname..." "INFO"
$pingLatency = Test-PingLatency -HostName $hostname -TimeoutSeconds $TimeoutSeconds
if ($pingLatency) {
Write-Log "Ping to $hostname : $pingLatency ms" "SUCCESS"
} else {
Write-Log "Ping to $hostname failed" "WARN"
}
}
# Test speed if enabled
$downloadSpeed = $null
if (-not $SkipSpeed) {
Write-Log "Testing response time to $displayUrl..." "INFO"
$downloadSpeed = Test-DownloadSpeed -Url $displayUrl -TimeoutSeconds $TimeoutSeconds
if ($downloadSpeed) {
Write-Log "Response time to $displayUrl : $downloadSpeed ms" "SUCCESS"
} else {
Write-Log "Speed test to $displayUrl failed" "WARN"
}
}
} else {
$status = 'FAILED'
$ipAddress = $null
Write-Log "URL $url - Connection FAILED" "ERROR"
}
$results += [PSCustomObject]@{
Type = 'URL'
Endpoint = $url
Status = $status
ResolvedIP = $ipAddress
PingLatency_ms = $pingLatency
DownloadSpeed_Kbps = $downloadSpeed
}
}
Write-Progress -Activity "Testing MEM Endpoints" -Completed
# Generate results summary
$endTime = Get-Date
$testDuration = $endTime - $script:startTime
$successfulTests = ($results | Where-Object { $_.Status -eq 'OK' }).Count
$failedTests = ($results | Where-Object { $_.Status -eq 'FAILED' }).Count
$successRate = if ($totalEndpoints -gt 0) { [math]::Round(($successfulTests / $totalEndpoints) * 100, 1) } else { 0 }
Write-Log "" "INFO"
Write-Log "=== TEST RESULTS SUMMARY ===" "INFO"
Write-Log "Test Duration: $($testDuration.ToString('hh\:mm\:ss'))" "INFO"
Write-Log "Total Endpoints Tested: $totalEndpoints" "INFO"
Write-Log "Successful Connections: $successfulTests" "SUCCESS"
Write-Log "Failed Connections: $failedTests" $(if($failedTests -eq 0){"SUCCESS"}else{"ERROR"})
Write-Log "Success Rate: $successRate%" $(if($successRate -eq 100){"SUCCESS"}else{"WARN"})
Write-Log "" "INFO"
# Log detailed results table
Write-Log "=== DETAILED RESULTS ===" "INFO"
$tableHeader = "Type".PadRight(5) + "Endpoint".PadRight(45) + "Status".PadRight(8) + "Resolved IP".PadRight(16)
if (-not $SkipPing) {
$tableHeader += "Ping(ms)".PadRight(10)
}
if (-not $SkipSpeed) {
$tableHeader += "Response(ms)".PadRight(15)
}
Write-Log $tableHeader "INFO"
Write-Log ("-" * $tableHeader.Length) "INFO"
foreach ($result in $results) {
$ipValue = if($result.ResolvedIP){$result.ResolvedIP.ToString()}else{"-"}
$line = $result.Type.PadRight(5) +
$result.Endpoint.PadRight(45) +
$result.Status.PadRight(8) +
$ipValue.PadRight(16)
if (-not $SkipPing) {
$line += $(if($result.PingLatency_ms){$result.PingLatency_ms}else{"-"}).ToString().PadRight(10)
}
if (-not $SkipSpeed) {
$line += $(if($result.DownloadSpeed_Kbps){$result.DownloadSpeed_Kbps}else{"-"}).ToString().PadRight(15)
}
$logLevel = if ($result.Status -eq 'OK') { "SUCCESS" } else { "ERROR" }
Write-Log $line $logLevel
}
# Performance statistics
if (-not $SkipPing -or -not $SkipSpeed) {
Write-Log "" "INFO"
Write-Log "=== PERFORMANCE STATISTICS ===" "INFO"
$successfulResults = $results | Where-Object { $_.Status -eq 'OK' }
if (-not $SkipPing) {
$pingResults = $successfulResults | Where-Object { $null -ne $_.PingLatency_ms }
if ($pingResults.Count -gt 0) {
$avgPing = [math]::Round(($pingResults | Measure-Object PingLatency_ms -Average).Average, 2)
$minPing = [math]::Round(($pingResults | Measure-Object PingLatency_ms -Minimum).Minimum, 2)
$maxPing = [math]::Round(($pingResults | Measure-Object PingLatency_ms -Maximum).Maximum, 2)
Write-Log "Ping Statistics:" "INFO"
Write-Log " Average Latency: $avgPing ms" "INFO"
Write-Log " Minimum Latency: $minPing ms" "INFO"
Write-Log " Maximum Latency: $maxPing ms" "INFO"
Write-Log " Tested Hosts: $($pingResults.Count)" "INFO"
}
}
if (-not $SkipSpeed) {
$speedResults = $successfulResults | Where-Object { $null -ne $_.DownloadSpeed_Kbps }
if ($speedResults.Count -gt 0) {
$avgSpeed = [math]::Round(($speedResults | Measure-Object DownloadSpeed_Kbps -Average).Average, 2)
$minSpeed = [math]::Round(($speedResults | Measure-Object DownloadSpeed_Kbps -Minimum).Minimum, 2)
$maxSpeed = [math]::Round(($speedResults | Measure-Object DownloadSpeed_Kbps -Maximum).Maximum, 2)
Write-Log "Speed/Response Time Statistics:" "INFO"
Write-Log " Average: $avgSpeed ms" "INFO"
Write-Log " Minimum: $minSpeed ms" "INFO"
Write-Log " Maximum: $maxSpeed ms" "INFO"
Write-Log " Tested Endpoints: $($speedResults.Count)" "INFO"
}
}
}
# Failed endpoints analysis
if ($failedTests -gt 0) {
Write-Log "" "INFO"
Write-Log "=== FAILED ENDPOINTS ANALYSIS ===" "ERROR"
$failedIPs = $results | Where-Object { $_.Type -eq 'IP' -and $_.Status -eq 'FAILED' }
$failedURLs = $results | Where-Object { $_.Type -eq 'URL' -and $_.Status -eq 'FAILED' }
if ($failedIPs.Count -gt 0) {
Write-Log "Failed IP Addresses ($($failedIPs.Count)):" "ERROR"
foreach ($failed in $failedIPs) {
Write-Log " - $($failed.Endpoint)" "ERROR"
}
}
if ($failedURLs.Count -gt 0) {
Write-Log "Failed URLs ($($failedURLs.Count)):" "ERROR"
foreach ($failed in $failedURLs) {
Write-Log " - $($failed.Endpoint)" "ERROR"
}
}
Write-Log "" "INFO"
Write-Log "RECOMMENDATION: Check firewall rules for the failed endpoints above." "WARN"
Write-Log "These endpoints are required for Microsoft Endpoint Manager functionality." "WARN"
}
Write-Log "" "INFO"
Write-Log "=== END OF TEST ===" "INFO"
Write-Log "Log file saved to: $script:LogFile" "SUCCESS"
# Console output summary if not quiet
if (-not $Quiet) {
Write-Host "`n" + "="*70 -ForegroundColor White
Write-Host "TEST RESULTS SUMMARY" -ForegroundColor White
Write-Host "="*70 -ForegroundColor White
Write-Host "Test Duration: $($testDuration.ToString('hh\:mm\:ss'))" -ForegroundColor Cyan
Write-Host "Total Endpoints: $totalEndpoints" -ForegroundColor Cyan
Write-Host "Successful: $successfulTests" -ForegroundColor $(if($successfulTests -eq $totalEndpoints){"Green"}else{"Yellow"})
Write-Host "Failed: $failedTests" -ForegroundColor $(if($failedTests -eq 0){"Green"}else{"Red"})
Write-Host "Success Rate: $successRate%" -ForegroundColor $(if($successRate -eq 100){"Green"}elseif($successRate -gt 80){"Yellow"}else{"Red"})
# Display results table
Write-Host "`nDetailed Results:" -ForegroundColor Cyan
$tableColumns = @(
@{Name="Type"; Expression={$_.Type}; Width=5},
@{Name="Endpoint"; Expression={$_.Endpoint}; Width=45},
@{Name="Status"; Expression={$_.Status}; Width=8},
@{Name="IP Address"; Expression={if($_.ResolvedIP){$_.ResolvedIP.ToString()}else{"-"}}; Width=15}
)
if (-not $SkipPing) {
$tableColumns += @{Name="Ping (ms)"; Expression={if($_.PingLatency_ms){$_.PingLatency_ms}else{"-"}}; Width=10}
}
if (-not $SkipSpeed) {
$tableColumns += @{Name="Response (ms)"; Expression={if($_.DownloadSpeed_Kbps){$_.DownloadSpeed_Kbps}else{"-"}}; Width=12}
}
$results | Format-Table $tableColumns -AutoSize
Write-Host "`n📄 Detailed log file created: $script:LogFile" -ForegroundColor Green
if ($failedTests -eq 0) {
Write-Host "✅ SUCCESS: All MEM endpoints are reachable!" -ForegroundColor Green
Write-Host "🎉 Microsoft Endpoint Manager should function properly." -ForegroundColor Green
} else {
Write-Host "⚠️ WARNING: $failedTests MEM endpoints are not reachable!" -ForegroundColor Red
Write-Host "💡 Check your firewall configuration for the failed endpoints." -ForegroundColor Yellow
}
}
# Set exit code
if ($failedTests -eq 0) {
exit 0
} else {
exit 1
}