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