Testing Well Formed URLs

by Jan 26, 2022

PowerShell is API-based so often, you don’t need to dive into regular expressions and text patterns. Instead, there is a multitude of specialized testing methods accessible in the .NET Framework. The hard part is rather to find and know them, not so much to run them and perform the tests.

For example, to test whether a URL is well-formed, try this:

$url = 'powershell.one'
$kind = [UriKind]::Absolute
[Uri]::IsWellFormedUriString($url, $kind)

The result would be false because “powershell.one” is no absolute URL. When you add “https://” to it, the result changes to true.


Twitter This Tip! ReTweet this Tip!