Download a file from a website


$url = “https://.exe”
$output = “c:\.exe”
$start_time = Get-Date
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, $output)
Write-output “Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)”

######if there is a problem with the certificate or you just want to ignore it, put the following at the beginning of the script######

add-type @”
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
“@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Ssl3, [Net.SecurityProtocolType]::Tls, [Net.SecurityProtocolType]::Tls11, [Net.SecurityProtocolType]::Tls12

sources:
https://til.intrepidintegration.com/powershell/ssl-cert-bypass.html

Leave a Reply

Your email address will not be published. Required fields are marked *