locked
Automate a file download from http by sending credentials to download it RRS feed

  • Question

  • Hi there,

    Can someone help me with a script to download a file over the web by sending credentials to that page (Username and password) as inputs.

    I need to integrate this script to a SQL Job which then imports the file into a SQL table. 

    Thanks in Advance.

    Regards,

    Sachin

    Friday, June 15, 2018 3:05 PM

Answers

  • $securepassword = ConvertTo-SecureString "password" -AsPlainText -Force $credentials = New-Object System.Management.Automation.PSCredential("username", $securepassword) Invoke-WebRequest -Uri "url goes here" -Credential $credentials

    The above script worked for me !!

    But the Output is what I am trying to figure out now. How to store the file to a location.

    The -Outfile doesnt work.

    Monday, June 18, 2018 4:08 PM

All replies

  • If the site doesn't support credentialed downloads then you are out of luck.

    $wc = [System.Net.WebClient]::new()
    $wc.Credentials = Get-Credential userid
    $wc.DownloadFile($url,$filepath)


    \_(ツ)_/

    Friday, June 15, 2018 3:10 PM
  • Thank you. 
    Friday, June 15, 2018 3:12 PM
  • 
    Monday, June 18, 2018 4:03 PM
  • $securepassword = ConvertTo-SecureString "password" -AsPlainText -Force $credentials = New-Object System.Management.Automation.PSCredential("username", $securepassword) Invoke-WebRequest -Uri "url goes here" -Credential $credentials

    The above script worked for me !!

    But the Output is what I am trying to figure out now. How to store the file to a location.

    The -Outfile doesnt work.

    Monday, June 18, 2018 4:08 PM