0

I have a daily running Powershell script which downloads a csv file from a site.

the code is :

$oppo_url = "https://itisawebsite?export=1&enc=UTF-8&xf=csv"
Start-Process $oppo_url

Start-Process will invoke Chrome which is my default browser and download the csv to my local Download folder, but I want the process to download the file to a designated folder, would it be possible?

I tried to add -WorkingDirectory 'C:\Users\myfolder\ but it didn't work.

bossangelo
  • 77
  • 5
  • 1
    Why not download the file using PowerShell instead of using Chrome for that? Examples [here](https://stackoverflow.com/questions/51225598/downloading-a-file-with-powershell), or [there](https://stackoverflow.com/questions/41618766/powershell-invoke-webrequest-fails-with-ssl-tls-secure-channel/41618979#41618979) – Theo Nov 18 '20 at 15:37
  • 1
    While I agree that keeping it all in PS is a good idea, another option would be to move the file (Move-Item) after the download. – EBGreen Nov 18 '20 at 16:01

2 Answers2

0

Use BITS its used internally to download stuff in the background, but you can use it as a simple file downloader:

Start-BitsTransfer -Source "https://itisawebsite?export=1&enc=UTF-8&xf=csv" -Destination "c:\path\to\yourfiles\itisawebsite.csv"

You can make it run as a background job by adding -Asynchronous and catch the return value from Start-BitsTransfer or use Get-BitsTransfer to check on the status of the downloads.

(Those & should really be & but ive left it exactly as your example)

MisterSmith
  • 2,884
  • 1
  • 10
  • 13
0

There are two Chrome extensions i have seen, but there might be more. These are, Downloads Router and RegExp Download Organizer. Where you should be able to specify which filetype, and then the .csv file can be downloaded to a specific folder you specify.

When PowerShell opens Chrome, these settings should be used.

Shaqil Ismail
  • 1,794
  • 1
  • 4
  • 5