Here's something I was looking for today on Google and couldn't find - how to get the website status code using PowerShell. Had to re-hash some C# code I found, and here it is:
try {
$SiteURL = "http://www.webtechy.co.uk/"
[System.Net.HttpWebRequest] $WebRequest = [System.Net.HttpWebRequest] [System.Net.WebRequest]::Create($SiteURL)
[System.Net.HttpWebResponse] $WebResponse = [System.Net.HttpWebResponse] $WebRequest.GetResponse()
$ResponseCode = $WebResponse.StatusCode
Write-Host "Response code for $SiteURL is $ResponseCode" -Foregoundcolor Green
} catch [Net.WebException] {
$ErrorMessage = $_.Exception.Message
Write-Host "The following error occurred: $ErrorMessage" -ForegroundColor Red
}
|
|
||||||||
|
This Month
Month Archive
About Me
Login
|
How to Get a Website Status Code Using PowerShell (e.g. 200, 400, 401, 500, etc.)
Comments
Re: How to Get a Website Status Code Using PowerShell (e.g. 200, 400, 401, 500, etc.)
More extensive iterating through multiple sites from an XML file here:
http://blog.webtechy.co.uk/blog/_archives/2010/8/2/4594289.html |
Search
Recent Articles
Favourite blogs
|
||||||
|
||||||||
