Test connection to site on port 80 and 443 with PowerShell, if port 443 fails, then do trace route

Test a connection to a site on port 80 and 443 every 15 seconds for 99999 times. If connection to port 443 fails the run a trace route to find the problem. A log is written to the desktop (currently logged on user's desktop) which prints date and time for very check made.

$username = [Environment]::UserName
while($i -lt 99999)
{
echo "Test #$i" | Out-File C:\users\$username\Desktop\log.txt -Append
date | Out-File C:\users\$username\Desktop\log.txt -Append
Test-NetConnection -ComputerName "www.YourDomainHere.dk" -Port 80 -InformationLevel "Detailed" | Out-File C:\users\$username\Desktop\log.txt -Append
$netTest = Test-NetConnection -ComputerName "www.YourDomainHere.dk" -Port 443 -InformationLevel "Detailed" | Tee-Object -FilePath C:\users\$username\Desktop\log.txt -Append
if($netTest.TcpTestSucceeded -ne "True")
{
tracert www.YourDomainHere.dk | Out-File C:\users\$username\Desktop\log.txt -Append
}
echo *** | Out-File C:\users\$username\Desktop\log.txt -Append
Start-Sleep -s 15
$i++
}

Kommentarer

Populære opslag fra denne blog

Microsoft Office 2016 and the AUTO_ACTIVATE property

Access Exchange online with Office 365 multi-factor authentication (MFA/2FA)

Disable logon and logoff events (event id 4624, 4625, 4634 (and all the other ones...))