# PowerShell – How to check response code from a website

Sprawdz kod odpowiedzi strony WWW przy pomocy PowerShell, aby potwierdzic dostepnosc, testowac endpointy i wykrywac bledy.

blog

28 Oct 2015 pl

There are times when you need to verify websites availability to be able to tell if it's up or not. Below you can find a simple approach to show whether the site is up or not. This comes useful in situations where website availability is crucial for your business.

### 🔒 Solution

```powershell
[string] $url = 'https://evotec.xyz'

function Get-WebStatus($url) {
    try {
        [net.httpWebRequest] $req = [net.webRequest]::create($url)
        $req.Method = "HEAD"
        [net.httpWebResponse] $res = $req.getResponse()

        if ($res.StatusCode -eq "200") {
            write-host "`nSite $url is up (Return code: $($res.StatusCode) - $([int] $res.StatusCode))`n" -ForegroundColor green
        } else {
            write-host "`nSite $url is down`n" ` -ForegroundColor red
        }
    } catch {

        write-host "`nThings went bad (dns issue?). Try again.`n" ` -ForegroundColor red
    }
}

Get-WebStatus $url
```

To be able to check for the status of a website quickly and efficiently one can use the following code. This code verifies whether site returns **Status Code 200. **In case of different code returns it's assumed the website is down.

## Powiązane projekty

Projekty powiązane z tagami, kategoriami i treścią tego wpisu.

[Wszystkie projekty](/projekty/)

Trwa dopasowywanie projektów...

[Powrót do bloga](/blog/)

## Powiązane wpisy

- [Check an API write after a PowerShell timeout](/blog/verify-uncertain-api-outcomes-powershell/)
- [Inspect and convert mixed Office archives with PSWriteOffice](/blog/inspect-and-convert-mixed-office-archives-pswriteoffice/)
- [Compose PDF reports and automate page workflows with PSWriteOffice](/blog/automate-pdf-reports-and-page-workflows-pswriteoffice/)

<!-- PowerForge markdown artifact sha256:02C0E97E08CFEF8E9C2B546B14C2BEEA29F246B73736F0D66F62D61D570B158E -->
