-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckMicrosoftEndpointsV2.ps1
More file actions
1427 lines (1246 loc) · 55.4 KB
/
Copy pathCheckMicrosoftEndpointsV2.ps1
File metadata and controls
1427 lines (1246 loc) · 55.4 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
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
[CmdletBinding()]
param(
[Parameter(HelpMessage="Specify which services to test. Use 'All' for all services or choose specific ones.")]
[ValidateSet('All', 'WindowsUpdate', 'Autopatch', 'Intune', 'Defender', 'AzureAD', 'Microsoft365', 'Store', 'Activation', 'Edge', 'Telemetry', 'Interactive')]
[string[]]$Services = 'Interactive',
[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 HTML report and save to specified path")]
[string]$HtmlReport,
[Parameter(HelpMessage="Open HTML report in browser after generation")]
[switch]$OpenReport
)
<#
.SYNOPSIS
Comprehensive connectivity, latency, and performance test for selectable Microsoft cloud service endpoints including Autopatch, Intune, Defender, and Microsoft 365.
GitHub Repository: https://github.com/roalhelm/PowershellScripts
.DESCRIPTION
This extensive connectivity testing script validates network access to critical Microsoft service endpoints
required for modern Windows environments and Microsoft cloud services. It covers all major services including
Windows Update for Business, Windows Autopatch, Microsoft Intune, Microsoft Defender, Azure AD, Microsoft 365,
Microsoft Store, Windows Activation, Microsoft Edge, and Windows Telemetry services.
The script performs the following operations:
1. Allows selective testing of specific Microsoft services or all services
2. Tests TCP connectivity to essential Microsoft service URLs on port 443 (HTTPS)
3. Measures ping latency to all reachable endpoints for performance analysis (optional)
4. Tests download speed/response time to evaluate network quality (optional)
5. Groups results by service backend for organized reporting
6. Provides color-coded output for easy identification of connectivity issues
7. Reports IP addresses of reachable endpoints for network troubleshooting
8. Displays comprehensive performance statistics and network quality ratings
9. Returns appropriate exit codes for automation and monitoring scenarios
10. Interactive menu system for easy service selection
Tested Service Categories:
- Windows Update for Business (WUfB)
- Windows Autopatch (automated patch management)
- Microsoft Intune (device management)
- Microsoft Defender (security services)
- Azure Active Directory (identity services)
- Microsoft 365 (productivity suite)
- Microsoft Store (app distribution)
- Windows Activation (licensing services)
- Microsoft Edge (browser services)
- Windows Telemetry (diagnostic data)
This tool is particularly useful for:
- Network administrators validating comprehensive firewall configurations
- Enterprise deployment teams ensuring all Microsoft services are accessible
- Troubleshooting connectivity issues across multiple Microsoft platforms
- Compliance verification for complete Microsoft cloud service access
- Pre-deployment network validation in complex enterprise environments
- Performance monitoring and network quality assessment
- Identifying slow connections or network bottlenecks to Microsoft services
- Targeted testing of specific Microsoft services to save time
- Automated testing scenarios with service-specific focus
.PARAMETER Services
Specifies which Microsoft services to test. Options:
- 'All': Test all available services
- 'WindowsUpdate': Windows Update for Business endpoints
- 'Autopatch': Windows Autopatch endpoints
- 'Intune': Microsoft Intune device management endpoints
- 'Defender': Microsoft Defender security endpoints
- 'AzureAD': Azure Active Directory authentication endpoints
- 'Microsoft365': Microsoft 365 productivity suite endpoints
- 'Store': Microsoft Store app distribution endpoints
- 'Activation': Windows activation and licensing endpoints
- 'Edge': Microsoft Edge browser service endpoints
- 'Telemetry': Windows diagnostic and telemetry endpoints
- 'Interactive': Show interactive menu to select services (default)
.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. Useful for automated scenarios.
.PARAMETER HtmlReport
Generates a comprehensive HTML report and saves it to the specified path.
If no extension is provided, '.html' will be added automatically.
If no path is provided, saves to current directory with timestamp.
.PARAMETER OpenReport
Automatically opens the generated HTML report in the default web browser.
Only works when -HtmlReport parameter is also specified.
.NOTES
File Name : CheckMicrosoftEndpointsV2.ps1
Author : Ronny Alhelm
Version : 2.1
Creation Date : October 13, 2025
Last Modified : October 14, 2025
Requirements : PowerShell 5.1 or higher
Network : Internet connectivity required
Ports : HTTPS (443) access to Microsoft endpoints, ICMP for ping tests
Permissions : No elevated privileges required
Duration : 1-10 minutes depending on selected services and test options
.CHANGES
Version 2.1 (2025-10-14):
- Added comprehensive HTML report generation with modern responsive design
- Implemented automatic browser opening for generated reports
- Enhanced visual presentation with color-coded status indicators
- Added performance statistics and service impact analysis in HTML format
- Improved report accessibility and professional appearance
Version 2.0 (2025-10-14):
- Added selective service testing with parameter support
- Implemented interactive menu system for service selection
- Added options to skip ping and speed tests for faster execution
- Added quiet mode for automated scenarios
- Enhanced parameter validation and help documentation
- Improved user experience with service-specific testing options
Version 1.1 (2025-10-14):
- Added comprehensive ping latency testing for all reachable endpoints
- Implemented download speed/response time measurements
- Enhanced performance statistics with min/max/average calculations
- Added network quality ratings and performance recommendations
- Improved progress indicators during extended testing phases
- Extended result tables to include latency and speed metrics
- Added color-coded performance indicators for quick assessment
Version 1.0 (2025-10-13):
- Initial release with comprehensive endpoint testing
- Added support for Windows Update for Business endpoints
- Included Microsoft Intune service endpoints
- Added Microsoft Defender endpoint validation
- Implemented color-coded output for better readability
- Added grouped results display by service backend
- Implemented proper exit codes for automation
- Added IP address resolution for troubleshooting
.VERSION
2.1
.EXAMPLE
.\CheckMicrosoftEndpointsV2.ps1
Runs in interactive mode, showing a menu to select which services to test.
.EXAMPLE
.\CheckMicrosoftEndpointsV2.ps1 -Services All
Tests all available Microsoft services with full connectivity, ping, and speed tests.
.EXAMPLE
.\CheckMicrosoftEndpointsV2.ps1 -Services Intune,Defender -SkipSpeed
Tests only Intune and Microsoft Defender endpoints with ping tests but skips speed tests.
.EXAMPLE
.\CheckMicrosoftEndpointsV2.ps1 -Services WindowsUpdate,Microsoft365 -Quiet
Tests Windows Update and Microsoft 365 endpoints in quiet mode with minimal output.
.EXAMPLE
.\CheckMicrosoftEndpointsV2.ps1 -Services AzureAD -SkipPing -SkipSpeed
Tests only Azure AD endpoints with basic connectivity testing only (fastest execution).
.EXAMPLE
# Use in automated monitoring for specific services
.\CheckMicrosoftEndpointsV2.ps1 -Services Intune,Defender -Quiet
if ($LASTEXITCODE -eq 0) {
Write-Host "Intune and Defender endpoints accessible"
} else {
Write-Host "Connectivity issues detected" -ForegroundColor Red
}
.EXAMPLE
# Test only critical services for quick validation
.\CheckMicrosoftEndpointsV2.ps1 -Services WindowsUpdate,AzureAD,Intune -SkipSpeed
.EXAMPLE
# Generate HTML report and open in browser
.\CheckMicrosoftEndpointsV2.ps1 -Services All -HtmlReport "NetworkReport.html" -OpenReport
.EXAMPLE
# Create HTML report with timestamp in filename
.\CheckMicrosoftEndpointsV2.ps1 -Services Intune,Defender -HtmlReport "Microsoft-Endpoints-Report-$(Get-Date -Format 'yyyyMMdd-HHmmss').html" -Quiet
.EXAMPLE
# Full test with comprehensive HTML report
.\CheckMicrosoftEndpointsV2.ps1 -Services All -HtmlReport "C:\Reports\Microsoft-Endpoints.html"
#>
# Function to show interactive service selection menu
function Show-ServiceSelectionMenu {
$selectedServices = @()
Write-Host "`n🔧 MICROSOFT ENDPOINT CONNECTIVITY TESTER V2.1" -ForegroundColor Cyan
Write-Host "="*60 -ForegroundColor DarkCyan
Write-Host "Select the Microsoft Services to test:" -ForegroundColor Yellow
Write-Host ""
$menuOptions = @(
@{ Key = "1"; Name = "Windows Update for Business"; Param = "WindowsUpdate" }
@{ Key = "2"; Name = "Windows Autopatch"; Param = "Autopatch" }
@{ Key = "3"; Name = "Microsoft Intune"; Param = "Intune" }
@{ Key = "4"; Name = "Microsoft Defender"; Param = "Defender" }
@{ Key = "5"; Name = "Azure Active Directory"; Param = "AzureAD" }
@{ Key = "6"; Name = "Microsoft 365"; Param = "Microsoft365" }
@{ Key = "7"; Name = "Microsoft Store"; Param = "Store" }
@{ Key = "8"; Name = "Windows Activation"; Param = "Activation" }
@{ Key = "9"; Name = "Microsoft Edge"; Param = "Edge" }
@{ Key = "10"; Name = "Windows Telemetry"; Param = "Telemetry" }
@{ Key = "A"; Name = "ALL SERVICES"; Param = "All" }
)
foreach ($option in $menuOptions) {
if ($option.Key -eq "A") {
Write-Host ""
Write-Host "[$($option.Key)] $($option.Name) 🚀" -ForegroundColor Green
} else {
Write-Host "[$($option.Key)] $($option.Name)" -ForegroundColor White
}
}
Write-Host ""
Write-Host "Enter the numbers of the desired services (e.g. 1,3,5 or A for all):" -ForegroundColor Cyan
Write-Host "Additional options:" -ForegroundColor Yellow
Write-Host " - Press 'P' to skip ping tests" -ForegroundColor Gray
Write-Host " - Press 'S' to skip speed tests" -ForegroundColor Gray
Write-Host " - Press 'H' to generate HTML report" -ForegroundColor Gray
Write-Host " - Press 'Q' for quiet mode" -ForegroundColor Gray
$userInput = Read-Host "`nYour selection"
# Parse input for service selection
$selections = $userInput -split ',' | ForEach-Object { $_.Trim().ToUpper() }
foreach ($selection in $selections) {
$option = $menuOptions | Where-Object { $_.Key -eq $selection }
if ($option) {
if ($option.Param -eq "All") {
return @("All")
} else {
$selectedServices += $option.Param
}
}
}
if ($selectedServices.Count -eq 0) {
Write-Host "No valid services selected. Using all services." -ForegroundColor Yellow
return @("All")
}
return $selectedServices
}
# Handle interactive mode
if ($Services -contains 'Interactive') {
$Services = Show-ServiceSelectionMenu
# Ask for additional options
Write-Host ""
$skipOptions = Read-Host "Options: Skip (P)ing, Skip (S)peed, Generate (H)TML-Report, (Q)uiet, or Enter for default"
if ($skipOptions -match 'P') { $SkipPing = $true }
if ($skipOptions -match 'S') { $SkipSpeed = $true }
if ($skipOptions -match 'Q') { $Quiet = $true }
if ($skipOptions -match 'H') {
$HtmlReport = "Microsoft-Endpoints-Report-$(Get-Date -Format 'yyyyMMdd-HHmmss').html"
$htmlChoice = Read-Host "Open HTML report in browser? (y/n)"
if ($htmlChoice -match '^(y|yes)') { $OpenReport = $true }
}
Clear-Host
}
# List of required Microsoft service endpoints (reviewed 2026)
$backendUrls = @{
'Windows Update for Business' = @(
'https://dl.delivery.mp.microsoft.com',
'https://download.windowsupdate.com',
'https://fe3.delivery.mp.microsoft.com',
'https://sws.update.microsoft.com',
'https://update.microsoft.com',
'https://windowsupdate.microsoft.com',
'https://www.delivery.mp.microsoft.com',
'https://www.dl.delivery.mp.microsoft.com',
'https://www.update.microsoft.com',
'https://www.windowsupdate.com',
'https://www.windowsupdate.microsoft.com',
'https://*.delivery.mp.microsoft.com',
'https://*.dl.delivery.mp.microsoft.com',
'https://*.update.microsoft.com',
'https://*.windowsupdate.com',
'https://*.windowsupdate.microsoft.com'
) | Sort-Object -Unique
'Windows Autopatch' = @(
<# 'https://api.update.microsoft.com',
'https://autopatch.microsoft.com',
'https://config.edge.skype.com',
'https://graph.microsoft.com',
'https://login.microsoftonline.com',
'https://manage.microsoft.com',
'https://nexusrules.officeapps.live.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'
#########################################################################
) | Sort-Object -Unique
'Intune' = @(
'https://device.login.microsoftonline.com',
'https://endpoint.microsoft.com',
'https://graph.microsoft.com',
'https://login.microsoftonline.com',
'https://manage.microsoft.com',
'https://*.manage.microsoft.com',
'https://*.dm.microsoft.com',
'https://portal.manage.microsoft.com',
'https://enrollment.manage.microsoft.com',
'https://enterpriseregistration.windows.net',
'https://certauth.enterpriseregistration.windows.net',
'https://r.manage.microsoft.com',
'https://i.manage.microsoft.com',
'https://p.manage.microsoft.com',
'https://c.manage.microsoft.com',
'https://m.manage.microsoft.com'
) | Sort-Object -Unique
'Microsoft Defender' = @(
'https://*.defender.microsoft.com',
'https://*.protection.outlook.com',
'https://*.security.microsoft.com',
'https://*.wdcp.microsoft.com',
'https://go.microsoft.com',
'https://wdcp.microsoft.com',
'https://definitionupdates.microsoft.com',
'https://www.microsoft.com',
'https://unitedstates.cp.wd.microsoft.com',
'https://europe.cp.wd.microsoft.com',
'https://asia.cp.wd.microsoft.com'
) | Sort-Object -Unique
'Azure Active Directory' = @(
'https://login.microsoftonline.com',
'https://device.login.microsoftonline.com',
'https://enterpriseregistration.windows.net',
'https://pas.windows.net',
'https://management.azure.com',
'https://policykeyservice.dc.ad.msft.net',
'https://aadcdn.msauth.net',
'https://aadcdn.msftauth.net'
) | Sort-Object -Unique
'Microsoft 365' = @(
'https://admin.microsoft.com',
'https://config.office.com',
'https://graph.microsoft.com',
'https://login.microsoftonline.com',
'https://officecdn.microsoft.com',
'https://protection.office.com',
'https://portal.office.com',
'https://*.cloud.microsoft',
'https://*.static.microsoft',
'https://*.usercontent.microsoft',
'https://*.office.com',
'https://*.office365.com',
'https://*.sharepoint.com',
'https://*.onedrive.com'
) | Sort-Object -Unique
'Microsoft Store' = @(
'https://storeedgefd.dsx.mp.microsoft.com',
'https://livetileedge.dsx.mp.microsoft.com',
'https://storecatalogrevocation.storequality.microsoft.com',
'https://img-prod-cms-rt-microsoft-com.akamaized.net',
'https://store-images.s-microsoft.com',
'https://displaycatalog.mp.microsoft.com',
'https://licensing.mp.microsoft.com',
'https://purchase.md.mp.microsoft.com'
) | Sort-Object -Unique
'Windows Activation' = @(
'https://activation.sls.microsoft.com',
'https://crl.microsoft.com',
'https://validation.sls.microsoft.com',
'https://activation-v2.sls.microsoft.com',
'https://purchase.md.mp.microsoft.com',
'https://licensing.mp.microsoft.com'
) | Sort-Object -Unique
'Microsoft Edge' = @(
'https://config.edge.skype.com',
'https://edge.microsoft.com',
'https://msedge.api.cdp.microsoft.com',
'https://dual-s-01.dual.dualstack.edge-enterprise.activity.windows.com',
'https://nav.smartscreen.microsoft.com',
'https://unitedstates.smartscreen-prod.microsoft.com'
) | Sort-Object -Unique
'Windows Telemetry' = @(
'https://v10c.events.data.microsoft.com',
'https://v20.events.data.microsoft.com',
'https://watson.telemetry.microsoft.com',
'https://umwatsonc.events.data.microsoft.com',
'https://ceuswatcab01.blob.core.windows.net',
'https://ceuswatcab02.blob.core.windows.net',
'https://eaus2watcab01.blob.core.windows.net',
'https://eaus2watcab02.blob.core.windows.net',
'https://weus2watcab01.blob.core.windows.net',
'https://weus2watcab02.blob.core.windows.net'
) | Sort-Object -Unique
}
# Service impact descriptions for failed connectivity
$serviceImpacts = @{
'Windows Update for Business' = @{
'Impact' = 'Windows Updates and Feature Updates cannot be downloaded'
'Symptoms' = 'Update errors, outdated security patches, missing feature updates'
}
'Windows Autopatch' = @{
'Impact' = 'Automatic patch management does not work'
'Symptoms' = 'Manual update management required, no automatic deployment schedules'
}
'Intune' = @{
'Impact' = 'Device enrollment, app deployment, and compliance checks do not work'
'Symptoms' = 'New devices cannot be enrolled, apps do not install, compliance reports missing'
}
'Microsoft Defender' = @{
'Impact' = 'Antivirus updates and cloud protection do not work'
'Symptoms' = 'Outdated virus signatures, no cloud-based threat analysis, limited protection'
}
'Azure Active Directory' = @{
'Impact' = 'Sign-in and device authentication may fail'
'Symptoms' = 'Login problems, device registration failed, SSO does not work'
}
'Microsoft 365' = @{
'Impact' = 'Office apps, SharePoint, and OneDrive do not work properly'
'Symptoms' = 'Office apps do not start, documents do not sync, Admin Center not accessible'
}
'Microsoft Store' = @{
'Impact' = 'App installation and updates from Microsoft Store do not work'
'Symptoms' = 'Store does not open, apps cannot be installed/updated'
}
'Windows Activation' = @{
'Impact' = 'Windows activation and license validation do not work'
'Symptoms' = 'Activation errors, license warnings, limited functionality'
}
'Microsoft Edge' = @{
'Impact' = 'Browser updates and enterprise features work with limitations'
'Symptoms' = 'SmartScreen disabled, no automatic updates, enterprise policies do not work'
}
'Windows Telemetry' = @{
'Impact' = 'Diagnostic data and error reports are not transmitted'
'Symptoms' = 'No Windows diagnostic data, error reports lost, update quality may be impaired'
}
}
# Function to test ping latency
function Test-PingLatency {
param (
[string]$HostName,
[int]$Count = 4
)
try {
$pingResults = Test-Connection -ComputerName $HostName -Count $Count -ErrorAction Stop
$avgLatency = ($pingResults | Measure-Object ResponseTime -Average).Average
return [math]::Round($avgLatency, 2)
}
catch {
return $null
}
}
# Function to test HTTPS response time (ms)
function Test-DownloadSpeed {
param (
[string]$Url,
[int]$TimeoutSeconds = 10
)
try {
# Create a test URL by adding a small file path (many Microsoft endpoints serve content)
$testUrl = $Url.TrimEnd('/') + "/favicon.ico"
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
$webClient = New-Object System.Net.WebClient
$webClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36")
try {
$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.ico doesn't work, try a HEAD request to measure server response time
$request = [System.Net.WebRequest]::Create($Url)
$request.Method = "HEAD"
$request.Timeout = $TimeoutSeconds * 1000
$stopwatch.Restart()
$response = $request.GetResponse()
$stopwatch.Stop()
$response.Close()
# Return response time in ms as a "speed" indicator (lower is better)
return [math]::Round($stopwatch.ElapsedMilliseconds, 2)
}
finally {
$webClient.Dispose()
}
}
catch {
return $null
}
return $null
}
# Function to display service impact warnings
function Show-ServiceImpactWarning {
param (
[string]$ServiceName,
[array]$FailedEndpoints
)
if ($serviceImpacts.ContainsKey($ServiceName)) {
Write-Host " ⚠️ IMPACT:" -ForegroundColor Yellow
Write-Host " • $($serviceImpacts[$ServiceName].Impact)" -ForegroundColor Yellow
Write-Host " 🔍 SYMPTOMS:" -ForegroundColor Cyan
Write-Host " • $($serviceImpacts[$ServiceName].Symptoms)" -ForegroundColor Cyan
Write-Host " 🚫 Affected endpoints: $($FailedEndpoints.Count)" -ForegroundColor Red
Write-Host ""
}
}
# Function to generate HTML report
function New-HtmlReport {
param (
[array]$Results,
[hashtable]$SelectedServices,
[array]$FailedServices,
[hashtable]$ServiceImpacts,
[bool]$SkipPing,
[bool]$SkipSpeed,
[string]$FilePath
)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$testDuration = (Get-Date) - $script:startTime
# Calculate statistics
$totalEndpoints = $Results.Count
$successfulEndpoints = ($Results | Where-Object { $_.Status -eq 'OK' }).Count
$failedEndpoints = $totalEndpoints - $successfulEndpoints
$successRate = if ($totalEndpoints -gt 0) { [math]::Round(($successfulEndpoints / $totalEndpoints) * 100, 1) } else { 0 }
$pingStats = $null
$speedStats = $null
if (-not $SkipPing) {
$pingResults = $Results | Where-Object { $_.Status -eq 'OK' -and $null -ne $_.PingLatency_ms }
if ($pingResults.Count -gt 0) {
$pingStats = @{
Average = [math]::Round(($pingResults | Measure-Object PingLatency_ms -Average).Average, 2)
Min = [math]::Round(($pingResults | Measure-Object PingLatency_ms -Minimum).Minimum, 2)
Max = [math]::Round(($pingResults | Measure-Object PingLatency_ms -Maximum).Maximum, 2)
Count = $pingResults.Count
}
}
}
if (-not $SkipSpeed) {
$speedResults = $Results | Where-Object { $_.Status -eq 'OK' -and $null -ne $_.DownloadSpeed_Kbps }
if ($speedResults.Count -gt 0) {
$speedStats = @{
Average = [math]::Round(($speedResults | Measure-Object DownloadSpeed_Kbps -Average).Average, 2)
Min = [math]::Round(($speedResults | Measure-Object DownloadSpeed_Kbps -Minimum).Minimum, 2)
Max = [math]::Round(($speedResults | Measure-Object DownloadSpeed_Kbps -Maximum).Maximum, 2)
Count = $speedResults.Count
}
}
}
# Generate HTML content
$htmlContent = @"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Microsoft Endpoint Connectivity Report</title>
<style>
* { box-sizing: border-box; }
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
border-radius: 10px;
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
overflow: hidden;
}
.header {
background: linear-gradient(135deg, #0078d4 0%, #106ebe 100%);
color: white;
padding: 30px;
text-align: center;
}
.header h1 { margin: 0; font-size: 2.5em; font-weight: 300; }
.header p { margin: 10px 0 0 0; opacity: 0.9; font-size: 1.1em; }
.summary {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
padding: 30px;
background: #f8f9fa;
}
.stat-card {
background: white;
padding: 25px;
border-radius: 8px;
text-align: center;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
border-left: 4px solid #0078d4;
}
.stat-value {
font-size: 2.5em;
font-weight: bold;
margin-bottom: 5px;
}
.stat-label {
color: #666;
font-size: 0.9em;
text-transform: uppercase;
letter-spacing: 1px;
}
.success { color: #28a745; border-left-color: #28a745 !important; }
.danger { color: #dc3545; border-left-color: #dc3545 !important; }
.warning { color: #ffc107; border-left-color: #ffc107 !important; }
.info { color: #17a2b8; border-left-color: #17a2b8 !important; }
.content { padding: 30px; }
.section { margin-bottom: 40px; }
.section h2 {
color: #333;
border-bottom: 2px solid #0078d4;
padding-bottom: 10px;
margin-bottom: 20px;
font-size: 1.8em;
font-weight: 300;
}
.service-group {
margin-bottom: 30px;
border: 1px solid #e0e0e0;
border-radius: 8px;
overflow: hidden;
}
.service-header {
background: #f1f3f4;
padding: 15px 20px;
font-weight: bold;
font-size: 1.2em;
color: #333;
display: flex;
align-items: center;
justify-content: space-between;
}
.service-status {
padding: 3px 12px;
border-radius: 20px;
color: white;
font-size: 0.8em;
font-weight: bold;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 0;
}
th, td {
text-align: left;
padding: 12px 15px;
border-bottom: 1px solid #e0e0e0;
}
th {
background: #f8f9fa;
font-weight: 600;
color: #333;
font-size: 0.9em;
text-transform: uppercase;
letter-spacing: 0.5px;
}
tr:hover { background-color: #f8f9fa; }
.status-ok {
background: #d4edda;
color: #155724;
padding: 4px 8px;
border-radius: 4px;
font-size: 0.8em;
font-weight: bold;
}
.status-failed {
background: #f8d7da;
color: #721c24;
padding: 4px 8px;
border-radius: 4px;
font-size: 0.8em;
font-weight: bold;
}
.ping-excellent { color: #28a745; font-weight: bold; }
.ping-good { color: #ffc107; font-weight: bold; }
.ping-poor { color: #dc3545; font-weight: bold; }
.footer {
background: #f8f9fa;
padding: 20px;
text-align: center;
color: #666;
font-size: 0.9em;
border-top: 1px solid #e0e0e0;
}
.alert {
padding: 15px 20px;
margin: 20px 0;
border-radius: 5px;
border-left: 4px solid;
}
.alert-danger {
background: #f8d7da;
border-left-color: #dc3545;
color: #721c24;
}
.alert-success {
background: #d4edda;
border-left-color: #28a745;
color: #155724;
}
.impact-section {
background: #fff3cd;
border: 1px solid #ffeaa7;
border-radius: 5px;
padding: 15px;
margin-top: 10px;
}
.impact-title {
font-weight: bold;
color: #856404;
margin-bottom: 10px;
}
.impact-list {
list-style: none;
padding: 0;
margin: 0;
}
.impact-list li {
padding: 5px 0;
border-bottom: 1px solid #ffeaa7;
}
.impact-list li:last-child {
border-bottom: none;
}
@media (max-width: 768px) {
.summary { grid-template-columns: repeat(2, 1fr); }
.container { margin: 10px; }
body { padding: 10px; }
table { font-size: 0.8em; }
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🌐 Microsoft Endpoint Connectivity Report</h1>
<p>Generated on $timestamp | Test Duration: $($testDuration.ToString("hh\:mm\:ss"))</p>
</div>
<div class="summary">
<div class="stat-card">
<div class="stat-value">$totalEndpoints</div>
<div class="stat-label">Tested Endpoints</div>
</div>
<div class="stat-card success">
<div class="stat-value">$successfulEndpoints</div>
<div class="stat-label">Successful</div>
</div>
<div class="stat-card danger">
<div class="stat-value">$failedEndpoints</div>
<div class="stat-label">Failed</div>
</div>
<div class="stat-card info">
<div class="stat-value">$successRate%</div>
<div class="stat-label">Success Rate</div>
</div>
"@
# Add ping statistics if available
if ($pingStats) {
$htmlContent += @"
<div class="stat-card">
<div class="stat-value">$($pingStats.Average)ms</div>
<div class="stat-label">Avg Latency</div>
</div>
"@
}
# Add speed statistics if available
if ($speedStats) {
$htmlContent += @"
<div class="stat-card">
<div class="stat-value">$($speedStats.Average)</div>
<div class="stat-label">Avg Response (ms)</div>
</div>
"@
}
$htmlContent += @"
</div>
<div class="content">
"@
# Add overall status alert
if ($failedEndpoints -eq 0) {
$htmlContent += @"
<div class="alert alert-success">
<strong>✅ Excellent!</strong> All tested Microsoft endpoints are reachable and functional.
</div>
"@
} else {
$htmlContent += @"
<div class="alert alert-danger">
<strong>⚠️ Warning!</strong> $failedEndpoints of $totalEndpoints Microsoft endpoints are not reachable.
This may lead to functional limitations in the affected services.
</div>
"@
}
# Add services section
$htmlContent += @"
<div class="section">
<h2>📋 Service Details</h2>
"@
# Generate service-specific tables
foreach ($serviceName in $SelectedServices.Keys) {
$serviceResults = $Results | Where-Object { $SelectedServices[$serviceName] -contains $_.URL }
$serviceFailures = ($serviceResults | Where-Object { $_.Status -eq 'FAILED' }).Count
$statusClass = if ($serviceFailures -eq 0) { "success" } else { "danger" }
$statusText = if ($serviceFailures -eq 0) { "✅ All OK" } else { "❌ $serviceFailures Errors" }
$htmlContent += @"
<div class="service-group">
<div class="service-header">
$serviceName
<span class="service-status $statusClass">$statusText</span>
</div>
<table>
<thead>
<tr>
<th>URL</th>
<th>Status</th>
<th>IP-Adresse</th>
"@
if (-not $SkipPing) {
$htmlContent += "<th>Latenz (ms)</th>"
}
if (-not $SkipSpeed) {
$htmlContent += "<th>Response (ms)</th>"
}
$htmlContent += @"
</tr>
</thead>
<tbody>
"@
foreach ($result in $serviceResults) {
$statusClass = if ($result.Status -eq 'OK') { 'status-ok' } else { 'status-failed' }
$pingClass = ""
$pingValue = "-"
if (-not $SkipPing -and $result.PingLatency_ms) {
$pingValue = $result.PingLatency_ms
if ($result.PingLatency_ms -lt 50) { $pingClass = "ping-excellent" }
elseif ($result.PingLatency_ms -lt 100) { $pingClass = "ping-good" }
else { $pingClass = "ping-poor" }
}
$speedValue = if (-not $SkipSpeed -and $result.DownloadSpeed_Kbps) { $result.DownloadSpeed_Kbps } else { "-" }
$ipValue = if ($result.IPAddress) { $result.IPAddress } else { "-" }
$htmlContent += @"
<tr>
<td>$($result.URL)</td>
<td><span class="$statusClass">$($result.Status)</span></td>
<td>$ipValue</td>
"@
if (-not $SkipPing) {
$htmlContent += "<td class=`"$pingClass`">$pingValue</td>"
}
if (-not $SkipSpeed) {
$htmlContent += "<td>$speedValue</td>"
}
$htmlContent += "</tr>"
}
$htmlContent += "</tbody></table>"
# Add service impact information if there are failures
if ($serviceFailures -gt 0 -and $ServiceImpacts.ContainsKey($serviceName)) {
$impact = $ServiceImpacts[$serviceName]
$htmlContent += @"
<div class="impact-section">
<div class="impact-title">⚠️ Possible Impact of Failures:</div>
<ul class="impact-list">
<li><strong>Functional Impact:</strong> $($impact.Impact)</li>
<li><strong>Possible Symptoms:</strong> $($impact.Symptoms)</li>
</ul>
</div>
"@
}
$htmlContent += "</div>"
}
$htmlContent += "</div>"
# Add performance statistics section if available
if ($pingStats -or $speedStats) {
$htmlContent += @"
<div class="section">
<h2>📊 Performance Statistics</h2>
"@
if ($pingStats) {
$htmlContent += @"
<div class="service-group">
<div class="service-header">🏓 Ping Latency Statistics</div>
<table>
<tr>
<th>Metric</th>
<th>Value</th>
<th>Rating</th>
</tr>
<tr>
<td>Average Latency</td>
<td class="$(if($pingStats.Average -lt 50){"ping-excellent"}elseif($pingStats.Average -lt 100){"ping-good"}else{"ping-poor"})">$($pingStats.Average) ms</td>
<td>$(if($pingStats.Average -lt 50){"🌟 Excellent"}elseif($pingStats.Average -lt 100){"👍 Good"}else{"⚠️ Needs Improvement"})</td>
</tr>
<tr>
<td>Best Latency</td>
<td class="ping-excellent">$($pingStats.Min) ms</td>