0

I need to download a 51gb zip file from the internet, to open the website you need to enter a password.

I want to do this with a function in PowerShell(PSVersion:5.1.18362.752), but I can't get any further. My function looks like this:

 $securepassword = "thepassword"

function Get-Files {
   
    $Properties = @{
        URI        = "https://theurl"
        Credential = $securepassword
    }
    Invoke-WebRequest @Properties -OutFile "C:\Users\$env:USERNAME\Desktop\thefiles.zip"

}

Can the parameter Credential only be used for Windows Credential?

Many thanks for the help

  • Get-Credential is just asking for string data. You can put whatever you want in it. It's your target that expects a specific format. You can read the help files for further details. – postanote Aug 06 '20 at 17:16

1 Answers1

2

I think you are using Credentials wrong. Credentials is not password only. It is username plus password, and they should be instance of ICredentials

Please note, that credentials can be passed this way ONLY for web pages that request HTTP 401 authentication. If web page uses form-based authentication, you should process it as non-standard case and credentials will not work, you will need to post data, keep cookies, etc.

$localPath = [System.IO.Path]::Combine(
    [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::DesktopDirectory),
    'OutFileName.zip')

$wc = [System.Net.WebClient]::new()
$wc.Credentials = [System.Net.NetworkCredential]::new($username, $plainTextPassword)
$wc.DownloadFile($uri, $localPath)
$wc.Dispose()
filimonic
  • 3,988
  • 2
  • 19
  • 26