none
Capture final URL port redirection RRS feed

  • Question

  • Hello Exparts,

    There is a requirement to check the final URL after redirection. I am able to get the result only when I am using -MaximumRedirection 0 else, the result is not showing up.

    $domain = get-content "<input file>"
    foreach ($uri in $domain)
    {
    $request = Invoke-WebRequest -Uri $uri -MaximumRedirection 0 -ErrorAction Ignore
    Write-Host $uri is pointing to $request.Headers.Location
    }

    The problem is, some domain has multiple redirection at multiple level (Load Balancer rewrite and then Server level rewrite) and the script is unable to detect that. It is showing only the first redirect or throwing error.

    Could you please suggest, how to get the final URL even if there is multiple redirection is in place.

    Best Regards,

    Prosenjit Sen

    $doma= get-content "<input file>"
    foreach ($uri in $domain)
    {
    $request = Invoke-WebRequest -Uri $uri -MaximumRedirection 0 -ErrorAction Ignore
    Write-Host $uri is pointing to $request.Headers.Location
    }

    $domain = get-content "<input file>"
    foreach ($uri in $domain)
    {
    $request = Invoke-WebRequest -Uri $uri -MaximumRedirection 0 -ErrorAction Ignore
    Write-Host $uri is pointing to $request.Headers.Loc


    Thanks & Regards, Prosenjit Sen.

    • Moved by Bill_Stewart Friday, July 27, 2018 9:15 PM This is not "scripts on demand"
    Thursday, May 31, 2018 5:52 PM