The below PowerShell script will use Invoke-WebRequest to download files from a URL that is requesting basic authentication.
#!powershell
# Setup Key Values
###################################
$URL=”http://yourserver//filetodownload.exe”
$DOWNLOADTARGETPATH= “C:\filetodownload.exe”
$USER_TO_ACCESS_DOWNLOAD = “YourUserName”
$USER_PW = “YourUserPassword”
# Forece TLS 1.2
###################################[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Download the file with authentication using Invoke-WebRequest
########################################################
write-host ” ” -ForegroundColor Green
write-host “Start Downloading files from: $URL” -ForegroundColor Green
write-host ” ” -ForegroundColor Green
$cred = New-Object System.Management.Automation.PsCredential(“$USER_TO_ACCESS_DOWNLOAD”, (ConvertTo-SecureString “$USER_PW” -AsPlainText -Force))
Invoke-WebRequest -UseBasicParsing $URL -Credential $cred -OutFile $DOWNLOADTARGETPATH -ErrorAction Stop