How to parse base path from a given URL?

Viewed 74

Given a URL like this: https://xyzt-pbi.co.com/reports/powerbi/Platform%20Status%20Reports/MSAS%20PBI%202019%20v10

How do i parse the server in powershell, in other words, i want this portion only: xyzt-pbi.co.com

1 Answers

Cast to [uri] (System.Uri) and access the resulting instance's .Host property:

PS> (
      [uri] 'https://xyzt-pbi.co.com/reports/powerbi/Platform%20Status%20Reports/MSAS%20PBI%202019%20v10'
    ).Host

xyzt-pbi.co.com
Related