-1

i need a powershell script to download a file from a website. we normaly need to open a browser first and authenticate to a website. how can i do this through an unintended script. thanks

i have tried several versions of scripts online but no luck..

$source = "http://chocolatey.org/install.ps1"
$dest = "C:\temp\chocolatey_install.ps1"
$WebClient = New-Object System.Net.WebClient
$WebProxy = New-Object System.Net.WebProxy("http://chocolatey.org:8080",$true)
#$WebProxy.Credentials = New-Object Net.NetworkCredential("user","password","domain.local")
$WebProxy.Credentials = New-Object Net.NetworkCredential("$user","$password","")
$WebClient.Proxy = $WebProxy
$WebClient.DownloadFile($source,$dest)
New contributor
arlan l falk is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • 1
    So your script doesn't work? What are the symptoms? What are the error messages? Please edit the question to include this vital information. – DavidPostill Jul 12 at 19:48
0

Perhaps you should send the Authorization header yourself, like this (untested) code:

$uri = "{url here}"
$username = "{username here}"
$password = "{password here}"
$b = [System.Text.Encoding]::UTF8.GetBytes($username + ":" + $password)
$p = [System.Convert]::ToBase64String($b)
$creds = "Basic " + $p
Invoke-WebRequest -Uri $uri -Method Get -Headers @{"Accept" = "*/*"; "Authorization" = $creds} 

Your Answer

arlan l falk is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.