File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
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 () }
You can’t perform that action at this time.
0 commit comments