The two key lines here are the IsWellFormedUriString and TryCreate . You can get more details about how these work from MSDN.function Test-Uri{<#.NOTESAuthor: Will SteeleLast Modified Date: 07/27/2012.EXAMPLETest-Uri -Uri http://www.msn.comTrue.EXAMPLETest-Uri -Uri http:/hax0r.comFalse#>param([ValidateNotNullOrEmpty()][String]$Uri)if([System.Uri]::IsWellFormedUriString($Uri, [System.UriKind]::RelativeOrAbsolute)){[System.Uri]::TryCreate($Uri, [System.UriKind]::RelativeOrAbsolute, [ref] $uri)}else{$false}}
- IsWellFormedUriString: Uri.IsWellFormedUriString Method
- TryCreate: Uri.TryCreate Method (String, UriKind, Uri%)
Again, this is a simple function, but, highly useful for anyone doing pen testing, analysis, checks, etc.