0

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,

1 Answers1

2

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&params&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&params&even #anchors
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206