-
Notifications
You must be signed in to change notification settings - Fork 1
/
Test-DeviceRegConnectivity.ps1
94 lines (67 loc) · 3.71 KB
/
Test-DeviceRegConnectivity.ps1
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
<#
Author: thewatchernode
Contact: author@blogabout.cloud
Published: 28th October 2019
.DESCRIPTION
Tool to assist with application delivery
Version Changes
: 0.1 Initial Script Build
: 1.0 Initial Build Release
.SYNOPSIS
Test-HybridDevicesInternetConnectivity PowerShell script.
.DESCRIPTION
Test-HybridDevicesInternetConnectivity is a PowerShell script that helps to test the Internet connectivity to the following Microsoft resources under the system context to validate the connection status between the device that needs to be connected to Azure AD as hybrid Azure AD joined device and Microsoft resources that are used during device registration process:
https://login.microsoftonline.com
https://device.login.microsoftonline.com
https://enterpriseregistration.windows.net
https://autologon.microsoftazuread-sso.com
.AUTHOR:
Andrew Price
Thank you to Mohammad Zmaili for the initial leg work :) #Respect
.EXAMPLE
.\Test-DeviceRegConnectivity
Description
-----------
Runs script with default values.
#>
Function RunPScript([String] $PSScript){
$GUID=[guid]::NewGuid().Guid
$Job = Register-ScheduledJob -Name $GUID -ScheduledJobOption (New-ScheduledJobOption -RunElevated) -ScriptBlock ([ScriptBlock]::Create($PSScript)) -ArgumentList ($PSScript) -ErrorAction Stop
$Task = Register-ScheduledTask -TaskName $GUID -Action (New-ScheduledTaskAction -Execute $Job.PSExecutionPath -Argument $Job.PSExecutionArgs) -Principal (New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest) -ErrorAction Stop
$Task | Start-ScheduledTask -AsJob -ErrorAction Stop | Wait-Job | Remove-Job -Force -Confirm:$False
While (($Task | Get-ScheduledTaskInfo).LastTaskResult -eq 267009) {Start-Sleep -Milliseconds 150}
$Job1 = Get-Job -Name $GUID -ErrorAction SilentlyContinue | Wait-Job
$Job1 | Receive-Job -Wait -AutoRemoveJob
Unregister-ScheduledJob -Id $Job.Id -Force -Confirm:$False
Unregister-ScheduledTask -TaskName $GUID -Confirm:$false
}
Function Test-DeviceRegConnectivity{
''
Write-Host "Checking Internet Connectivity..." -ForegroundColor Yellow
$TestResult = RunPScript -PSScript "(Test-NetConnection -ComputerName login.microsoftonline.com -Port 443).TcpTestSucceeded"
if ($TestResult -eq $true){
Write-Host "Connection to login.microsoftonline.com .............. Succeeded." -ForegroundColor Green
}else{
Write-Host "Connection to login.microsoftonline.com ................. failed." -ForegroundColor Red
}
$TestResult = RunPScript -PSScript "(Test-NetConnection -ComputerName device.login.microsoftonline.com -Port 443).TcpTestSucceeded"
if ($TestResult -eq $true){
Write-Host "Connection to device.login.microsoftonline.com ...... Succeeded." -ForegroundColor Green
}else{
Write-Host "Connection to device.login.microsoftonline.com .......... failed." -ForegroundColor Red
}
$TestResult = RunPScript -PSScript "(Test-NetConnection -ComputerName autologon.microsoftazuread-sso.com -Port 443).TcpTestSucceeded"
if ($TestResult -eq $true){
Write-Host "Connection to autologon.microsoftazuread-sso.com ...... Succeeded." -ForegroundColor Green
}else{
Write-Host "Connection to autologon.microsoftazuread-sso.comm .......... failed." -ForegroundColor Red
}
$TestResult = RunPScript -PSScript "(Test-NetConnection -ComputerName enterpriseregistration.windows.net -Port 443).TcpTestSucceeded"
if ($TestResult -eq $true){
Write-Host "Connection to enterpriseregistration.windows.net ..... Succeeded." -ForegroundColor Green
}else{
Write-Host "Connection to enterpriseregistration.windows.net ........ failed." -ForegroundColor Red
}
''
}
Test-DeviceRegConnectivity