Skip to content

Instantly share code, notes, and snippets.

Last active May 9, 2022 16:30
What would you like to do?
PowerShell View Remote Server Certificate Details
# This example lacks error checking
# late binding, call main AFTER defining check_ssl dependency
function main() { check_ssl -fqdn "" -port 443 }
function check_ssl($fqdn, $port) {
$tcpsocket = New-Object Net.Sockets.TcpClient($fqdn, $port)
$tcpstream = $tcpsocket.GetStream()
$sslStream = New-Object Net.Security.SslStream($tcpstream, $false)
$certinfo = New-Object security.cryptography.x509certificates.x509certificate2($sslStream.RemoteCertificate)
# look at $tcpsocket.Client.RemoteEndPoint to see Server IP the client is using for connection
$certinfo | fl
$certinfo.Extensions | where {$_.Oid.FriendlyName -like 'subject alt*'} | `
foreach { $_.Oid.FriendlyName; $_.Format($true) }
$tcpsocket.Close() # Dispose() missing from older .NET, use Close()
main # run late-binding function defined at top of script
# Based on
# Subject Alternative Name info is displayed using technique suggested by Craig Landis
# ...
Copy link

This might bypass the system or user proxy settings. If so, it would be nice to have some way to test SSL using the proxy settings too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment