detect URL redirect

by sege5641 at 2013-05-01 07:31:33

What I need is a vary simple command that allows powershell to detect if the URL it has just opened has been redirected away from its set destination.

Basically this is what I’m looking at:

netsh interface ip set dns “wifi” static primary
ipconfig /flushdns
Start-Process -FilePath ""

I want to open a different website if it gets redirected and doesn’t land on the set website address.
by DonJ at 2013-05-04 08:50:50
Not the way you’re doing it, no. You’re starting a Web browser, and it is handling the redirect. You’d need to manually write a WebRequest object, since that would let you receive the redirect instruction yourself and decide what to do with it.
by sege5641 at 2013-05-04 09:54:21
Could I get some direction on how that would work?
by DonJ at 2013-05-04 10:19:48
That’s really outside PowerShell. I’d suggest looking for a WebRequest tutorial, if you can find one, or asking at StackOverflow - this is .NET Framework programming, really. For example, … webrequest discusses turning off auto-redirect so you can handle it manually. You can do this in PowerShell, but it’s all .NET code.