2

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
4
  • Try pipe Invoke-WebRequest to Out-File Commented Feb 21, 2018 at 9:56
  • works like a charm,, thank you. feel free to add it as answer so I can accept it Commented Feb 21, 2018 at 10:13
  • Actually Invoke-Webrequest has a -OutFile parameter that you can use to specify the path and filename of where you want the file to be saved. Commented Feb 21, 2018 at 10:17
  • yes thats what I did, no pipe needed Commented Feb 21, 2018 at 10:23

1 Answer 1

3

Use the -OutFile parameter of Invoke-WebRequest:

Invoke-WebRequest -Uri "https://dosomething.do" -OutFile C:\some\path\to\yourfile.csv
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.