Hoping someone can help with this.
I built a script based on this link
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$urlStr = Read-Host "Please enter URL to check"
[uri]$urlStr
# First we create the request.
$HTTPS_Request = [System.Net.WebRequest]::Create("$urlStr")
# We then get a response from the site.
$HTTPS_Response = $HTTPS_Request.GetResponse()
# We then get the HTTP code as an integer.
$HTTPS_Status = [int]$HTTPS_Response.StatusCode
$HTTPS_StatusDesc = [string]$HTTPS_Response.StatusDescription
#Write-Host "HTTP CODE: $HTTPS_Status"
do {
If ($HTTPS_Status -eq 301) {
Write-Host "HTTP CODE: $HTTPS_Status"
Write-Host "HTTP CODE DESCRIPTION: $HTTPS_StatusDesc"
Write-Host "Landing page moved permanently and redirects to another URL."
Write-Host "Please update Landing page to new URL"
}
ElseIf ($HTTPS_Status -eq 302) {
Write-Host "HTTP CODE: $HTTPS_Status"
Write-Host "HTTP CODE DESCRIPTION: $HTTPS_StatusDesc"
Write-Host "If this occurs once, then no issues"
Write-Host "If this occurs more than once, please update Landing page to new URL"
}
} while ($HTTPS_Status -ge 300 -and $HTTPS_Status -lt 400)
If ($HTTPS_Status -eq 200) {
Write-Host "HTTP CODE: $HTTPS_Status"
Write-Host "HTTP CODE DESCRIPTION: $HTTPS_StatusDesc"
Write-Host "Landed on page"
}
ElseIf ($HTTPS_Status -gt 400) {
Write-Host "HTTP CODE: $HTTPS_Status"
Write-Host "HTTP CODE DESCRIPTION: $HTTPS_StatusDesc"
Write-Host "Error - issue with Landing page. Please investigate."
}
# Finally, we clean up the http request by closing it.
$HTTPS_Response.Close()
$HTTPS_Response.Dispose()
#Read-Host -Prompt “Press Enter to exit”
Currently, the above is built to handle one URL at a time, which was fine for me as the amount of links and usage of the script was low overall so I left it as is.
But as the usage and URLs are increasing for the above script, I am hoping to have the code further modified into running multiple URLs at the same time.
My idea is to save the URLs into a TXT or CSV file and have it read, line-by-line, and run the script per line. It would then record the response and output the HTTP code (e.g. 200, 404, etc...) into a CSV (or the original CSV file) and input the data there as well.
If possible, I'd like to record the output from "$HTTP_Response" and add that in as well, but this would be a secondary objective.
Any help would be much appreciated.
Thanks.
Rajiv.