Last active
May 9, 2022 16:30
-
-
Save notesbytom/2850d97fa5038053f8580730b8ee6e05 to your computer and use it in GitHub Desktop.
PowerShell View Remote Server Certificate Details
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This example lacks error checking | |
# late binding, call main AFTER defining check_ssl dependency | |
function main() { check_ssl -fqdn "your.fqdn.com" -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) | |
$sslStream.AuthenticateAsClient($fqdn) | |
$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 https://blogs.technet.microsoft.com/parallel_universe_-_ms_tech_blog/2014/06/26/reading-a-certificate-off-a-remote-ssl-server-for-troubleshooting-with-powershell/ | |
# Subject Alternative Name info is displayed using technique suggested by Craig Landis | |
# ... https://social.technet.microsoft.com/wiki/contents/articles/1447.display-subject-alternative-names-of-a-certificate-with-powershell.aspx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.