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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s