I am an idiot for this... Does anybody has examples on how to call WinINet InternetCrackUrl from powershell? The API ref is here.
I want a very robust way to parse URLs, I have tried some regex samples out there and none seem to do the job,
I am an idiot for this... Does anybody has examples on how to call WinINet InternetCrackUrl from powershell? The API ref is here.
I want a very robust way to parse URLs, I have tried some regex samples out there and none seem to do the job,
I'd suggest using the [System.Uri]
type already built-in to .NET - PowerShell even ships with a [uri]
type accelerator for it!
$aURL = [uri]'https://some.address.tld/with/a/path?and=a&few=query¶ms&even#anchors'
I invite you to explore the properties of the resulting [uri]
object yourself, but these are probably the main ones you'd be interested in
$aURL |Format-Table Scheme,Authority,AbsolutePath,Query,Fragment
Scheme Authority AbsolutePath Query Fragment
------ --------- ------------ ----- --------
https some.address.tld /with/a/path ?and=a&few=query¶ms&even #anchors