Analyzing URLs

by Feb 10, 2009

URLs contain a lot of information which can be automatically parsed by PowerShell. Simply convert a URL to the System.URI type. Once you did this, all information contained in the URL is accessible via individual properties:

$result = [System.uri]'http://powershell.com/cs/forums/'
$result

"You are using Port $($result.port)."
"Page comes from $($result.Authority)."
"Served using $($result.Scheme)."