如何仅解析 AbsoluteUri 和 LocalPath?

How to parse the AbsoluteUri along with LocalPath only?

假设我有以下

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

我想获取这部分以及第一个本地路径,即 https://www.example.com/folder

换句话说,我不想要 folder2 等...因为我计划将这部分附加到 api 路径,所以最终我会得到类似 $URL + "/api/v2.0/"https://www.example.com/folder/api/v2.0/

我用 -split

弄明白了
($URL -split "folder2")[0]

这给出 https://www.example.com/folder/