~mjorgensen/windows-dotfiles

d9ead5c466354c8d9e808a1a6dc97bcd27f9e7be — Matthew Jorgensen 12 days ago 8d14cea master
Add option to run Monitor-HttpHost once.
1 files changed, 16 insertions(+), 5 deletions(-)

M functions.ps1
M functions.ps1 => functions.ps1 +16 -5
@@ 16,19 16,30 @@ function Monitor-HttpHost {
        [string]$Uri,

        [Parameter(Mandatory=$false)]
        [int]$SleepSeconds = 15
    )
        [int]$SleepSeconds = 15,

        [Parameter(Mandatory=$false)]
        [switch]$Once
    )

    Write-Host "Monitoring host $Uri at an internal of $SleepSeconds seconds."
    while($true){
    if ($Once) {
        try {
            $req = Invoke-WebRequest -Uri $Uri -DisableKeepAlive
            Write-Host $req.StatusCode
        } catch {
            Write-Host "Could not connect. $($Error[0])"
        }
        Start-Sleep -Seconds $SleepSeconds
    } else {
        Write-Host "Monitoring host $Uri at an internal of $SleepSeconds seconds."
        while($true){
            try {
                $req = Invoke-WebRequest -Uri $Uri -DisableKeepAlive
                Write-Host $req.StatusCode
            } catch {
                Write-Host "Could not connect. $($Error[0])"
            }
            Start-Sleep -Seconds $SleepSeconds
        }
    }
}