Skip to content

Instantly share code, notes, and snippets.

@tcartwright
Last active February 20, 2025 14:33
Show Gist options
  • Save tcartwright/1cda5676a81a4cad49c1e33c4897c3eb to your computer and use it in GitHub Desktop.
Save tcartwright/1cda5676a81a4cad49c1e33c4897c3eb to your computer and use it in GitHub Desktop.
POWERSHELL: Test https cert
Clear-Host
$hostName = "www.microsoft.com"
$req = [System.Net.HttpWebRequest]::Create("https://$hostName")
$req.GetResponse().Dispose()
[System.Security.Cryptography.X509Certificates.X509Certificate2]$cert = $req.ServicePoint.Certificate
#$cert | Format-List *
$props = $cert | Select-Object Subject,
@{Name="ValidFrom"; Expression={$_.NotBefore}},
@{Name="ValidTo"; Expression={$_.NotAfter}},
@{Name="IsValid"; Expression={$_.Verify() -and (Get-Date) -le ([DateTime]::Parse($_.GetExpirationDateString())) }},
@{Name="Encryption"; Expression={$_.SignatureAlgorithm.FriendlyName}},
@{Name="DnsNames"; Expression={$_.DnsNameList.Unicode}},
Issuer
$props | Out-Host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment