I have a list of thousands of URLs contained in a CSV file. They're full length, including folders, variables, etc. I'd like to produce a list of the domains for further analysis. I found this relevant SO thread, but I'm new to Powershell and I'm not seeing how to iterate this over the lines of a CSV.
My CSV has only one column:
http://something.net/prod/case_studies.asp
http://www.another.com/prod/group/gold/price_guarantee.asp
http://www.goodsite.co.uk/prod/case.asp?utm_source=google&utm_medium=search
http://wheel.net/prod/studious.asp
http://www.buystrop.com/gap/index.php?page_id=2345&group_id=9876
Here's what I'd like to end up with:
something.net
www.another.com
www.goodsite.co.uk
wheel.net
www.buystrop.com
I've tried several iterations of the code I found in the other thread, but nothing has worked yet. Either I get errors, or the output is blank.
Edit: Here's the code that I've tried so far:
$file = Get-Content 'file.csv'
$domains = ForEach ($p in $file) {select ([System.Uri]$p).Host}
That gives no error, the code runs but $domains is empty.
$domains = ForEach-Object {$file | select-object [System.Uri]$file.Host}
$domains = ForEach-Object [System.Uri]$file.Host
These both give an error indicating that it's looking at the entire file, not looping through each line. I've now tried a few dozen variations on these, I haven't yet figured out how parse the URL in each line.
$domainsas$domians.