Skip to content

Instantly share code, notes, and snippets.

@ismits
Created April 26, 2019 18:35
Show Gist options
  • Save ismits/7e35d8a589426e7aecc040ba65635e77 to your computer and use it in GitHub Desktop.
Save ismits/7e35d8a589426e7aecc040ba65635e77 to your computer and use it in GitHub Desktop.
Dump SSL certificate to a temp file from URI
function Write-CertificateToTempFile($uri) {
$http = [Net.WebRequest]::Create($uri)
try {
$resp = $http.GetResponse()
$cert = $http.ServicePoint.Certificate
$byte = $cert.Export([Security.Cryptography.X509Certificates.X509ContentType]::Cert)
}
catch {
Write-Warning "Errors encoutered during connection attempt:`n$_"
Write-Warning "Cannot continue. Quitting."
}
$file = [io.path]::GetTempFileName()
Set-Content -Value $byte -Encoding Byte -Path $file
return $file
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment