Jaa


Quick test to see which URL's are still valid

On an internal mailing list about PowerShell, the question came up how to test a set of url's to see which ones are still "valid" (meaning you can still access them successfully).  Since I thought my answer may be useful to others externally as well, I'm pasting it here:

I would think the easiest thing would be to create a new System.Net.WebClient and test whether you can DownloadString the url without an exception, something like:

 C:\ > $urls = 'https://www.live.com','https://www.notlivebutnotdeadyet.com','https://www.dead.com'
C:\ > $wc = new-object system.net.webclient
C:\ > $urls | %{ trap { continue } . { $null = $wc.DownloadString($_) ; $_ } }
https://www.live.com
https://www.dead.com