Search code examples
powershell-5.0

How to parse the AbsoluteUri along with LocalPath only?


Suppose I have the following

[uri]$URL = "https://www.example.com/folder/folder2"

I would like to get this part along with the first local path, i.e. https://www.example.com/folder

In other words, I dont want folder2 etc... because i plan to append this portion to an api path, so eventually i'd have something like $URL + "/api/v2.0/" or https://www.example.com/folder/api/v2.0/


Solution

  • I figured it out using -split

    ($URL -split "folder2")[0]
    

    this gives https://www.example.com/folder/