Note: This tip requires PowerShell 3.0 or above.
In an earlier tip, we looked at how we can retrieve the redirected URL using a .NET class. In today’s tip, we will look at how we can simplify that process using an in-built PowerShell 3.0 cmdlet – Invoke-WebRequest.
$uri = 'http://go.microsoft.com/fwlink/?LinkID=210601' $request = Invoke-WebRequest -Uri $uri -MaximumRedirection 0 -ErrorAction Ignore if($request.StatusDescription -eq 'found') { $request.Headers.Location }
This is it. Much simpler than the earlier approach!