How to download files from a url using powershell

Viewed 23

I am new to PowerShell. I need to download log files from a URL address. The folder has multiple files for each day. The generic format of the file name is plus_220919030001.csv (yymmddhhmmss.csv). I've not been able to find any way to do this. If I use the exact file name I have been able to use Invoke-RestMethod but I need to get multiple files and I don't know the filenames.

1 Answers

The way I would think about it would be Invoke-WebRequest the url with the folders into a variable and then iterate through them. A really basic test example on a local file system would be something like

$files = Get-ChildItem
foreach ($file in $files) {Write-Output $file.Name}

which would get you the listing as an object you can iterate through. Just replace Get-ChildItem with your Invoke, and Write-Output with something useful to do with each in the loop.

Related