If you need to verify a web address, it’s natural to look into Invoke-WebRequest, capturing the results and check the StatusCode if the request was successful. There is just one problem…
If the URI is invalid, Invoke-WebRequest throws a terminating error, and no amount of -ErrorAction SilentlyContinue will stop it from doing this.
I got fed up with having to code around this so I decided to write a helper function that “fixes” this problem.
It will take a string or a URI object as input and the output is a boolean; either True or False, similar to how Test-Path works.
There is nothing fancy going on here, just working around a quirk/bug in Invoke-WebRequest, but if you find a bug, or have an idea for a new feature you would like me to add, please let me know in the comments below.