Hi I need a little help. (complete n00b)
I need to get all the CSV files from a homepage (specific folder) and download them to a local folder.
This first part works and I get a nice list of all the *.CSV files:
$WebResponse = Invoke-WebRequest "https://somepage.dot/"
$links2 = $WebResponse.links | select href | where {$_.href -like '*csv*'}
The next part, not so much I have serveral issues:
-
I need to trim the filename and I know it’s because I’m doing some thing wrong, but I just can not figure out what.
-
Invoke-webrequest also has problems with the trim caracters, so it throws an error: Invoke-WebRequest : Cannot bind parameter ‘Uri’. Cannot convert the “@{href=https://somepage.dot/somefile.csv}” value of type “Selected.System.Management.Automation.PSCustomObject” to type “System.Uri”.
ForEach ($href in $links2)
{
$FileName = Split-Path $href -leaf
$filelocation = "C:\Temp\" + $FileName.Trim("}")
Invoke-WebRequest $href -OutFile $filelocation
}
I know it must be something basic I’m missing.
Kind regards Jgaard.