Last active
October 28, 2022 10:47
-
-
Save barryokane/275eb5006b3631a732935477bdff71b0 to your computer and use it in GitHub Desktop.
Powershell script to loop over a list of URLs, make a HTTP HEAD request and check for (first) 301 response.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------- | |
# Script to loop over a list of URLs, make a HTTP HEAD request and check for (first) 301 response | |
# INPUT: A txt file with one URL per line | |
# | |
# OUTPUT: A CSV file with columns for: | |
# - RequestURI = the URI from than line in input file | |
# - StatusCode = response status code (blank if error code!) | |
# - Error = Error message (for 404 or 500 errors) | |
# | |
$linksFilePath = "C:\Temp_Stuff\{your input file}.txt" | |
$outCSVPath = "C:\Temp_Stuff\{your output file}.csv" | |
get-content $linksFilePath | | |
Foreach { $uri = $_; try { Invoke-WebRequest -Uri $uri -Method HEAD -MaximumRedirection 0 -ErrorAction SilentlyContinue -UseBasicParsing } catch { | |
New-Object -TypeName psobject -Property @{ Error = $_ } } } | | |
Select @{Name="RequestURI";Expression={$uri}}, StatusCode, @{Name="RedirectTo";Expression={$_.Headers["Location"]}}, Error | | |
Export-Csv $outCSVPath |
Tnx for this.Its saved my day , when i need checking for nodes with forbiden access mesages.
By Karel
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@shivagra : this little powershell script loops over a list of URLs and lists any redirects. So, maybe you could create and "input file" with all your locale Urls (one per line) and use this script?