Search code examples
powershellpowershell-5.0web-administration

Download a file which is generated through https call using powershell


Currently I have this short piece of code. The URL https://dosomething.do generates a .csv file. I can run the powershell code and in the shell I can see the content of the file. However the file itself is not downloaded. I would like to specify where to save it after a download. What are my options here?

$securepassword = ConvertTo-SecureString "xxx" -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential("hxxx", $securepassword)
Invoke-WebRequest -Uri "https://dosomething.do" -Credential $credentials

Solution

  • Use the -OutFile parameter of Invoke-WebRequest:

    Invoke-WebRequest -Uri "https://dosomething.do" -OutFile C:\some\path\to\yourfile.csv