Skip to content

Commit 9f411ab

Browse files
authored
Add files via upload
1 parent a4b3727 commit 9f411ab

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Scripts/Monitor-Website.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
$URL = Read-Host "Enter the URL of the website you want to monitor"
2+
[int]$Interval = Read-Host "Set the interval seconds"
3+
4+
$Request = [System.Net.WebRequest]::Create($URL)
5+
$Response = $Request.GetResponse()
6+
$QueryStatus = [int]$Response.StatusCode
7+
8+
Clear-Host
9+
10+
Write-Host "Starting Monitoring to: $URL" -ForegroundColor Yellow
11+
Write-Host " "
12+
13+
while ($true) {
14+
$Date = Get-Date -UFormat "%m/%d/%Y %T"
15+
$StateMessage = "$Date | The site status is:"
16+
17+
if ($QueryStatus -eq 200) {
18+
Write-Host "$StateMessage UP!" -ForegroundColor Green
19+
}
20+
else {
21+
Write-Host "$StateMessage DOWN!" -ForegroundColor Red
22+
}
23+
Start-Sleep -Seconds $Interval
24+
}
25+
26+
27+
# Finally, we clean up the http request by closing it.
28+
if ($Response -ne $null) { $Response.Close() }

0 commit comments

Comments
 (0)