Skip to content

Instantly share code, notes, and snippets.

@burgiuk
Last active March 20, 2019 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burgiuk/0776249210c66a6c8d225c9b28724fd2 to your computer and use it in GitHub Desktop.
Save burgiuk/0776249210c66a6c8d225c9b28724fd2 to your computer and use it in GitHub Desktop.
PowerShell script to check urls
$siteURL='http://example.com/'
# Set file name
$File = '.\urls.txt'
# Process lines of text from file and assign result to $NewContent variable
$NewContent = Get-Content -Path $File |
ForEach-Object {
# First we create the request.
$HTTP_Request = [System.Net.WebRequest]::Create($siteURL + $_)
try{
# We then get a response from the site.
$HTTP_Response = $HTTP_Request.GetResponse()
}
catch [System.Net.WebException] {
# HTTP error, grab response from exception
$HTTP_Response = $_.Exception.Response
}
finally {
# Grab status code and dispose of response stream
$HTTP_Status = [int]$HTTP_Response.StatusCode
$HTTP_Response.Dispose()
}
$siteURL+"$_ - $HTTP_Status"
}
# Write content of $NewContent varibale back to file
$NewContent | Out-File -FilePath $File -Encoding Default -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment