Cutting part of url in powershell
I have multiple urls that would have to cut and separate the first part of each url i.e. example1.com
, example2.com
, example3.com
Of each line and stored in a variable
Content in url.csv
https://example1.com/v1/test/f3de-a8c6-464f-8166-9fd4 https://example2.com/v1/test/14nf-d7jc-54lf-fd90-fds8 https://example3.com/v1/test/bd38-17gd-2h65-0j3b-4jf6
Script:
$oldurl = Import-CSV "url.csv"
$newurl = $oldurl.list -replace "https://"
This will override https://
, however the rest of them cannot be hardcoded as these values ββcan change.
What can be changed to change the code needed to shorten anything from and after /v1/
along with https://
?
source to share
$list = @(
"https://example1.com/v1/test/f3de-a8c6-464f-8166-9fd4",
"https://example2.com/v1/test/14nf-d7jc-54lf-fd90-fds8",
"https://example3.com/v1/test/bd38-17gd-2h65-0j3b-4jf6"
)
$result = $list | %{
$uri = [System.Uri] $_
$uri.Authority
}
$result
Look at the System.Uri properties to potentially gather the information you need in the list of results.
source to share