Home » PowerShell » PowerShell Get SSL Certificate Thumbprint

PowerShell Get SSL Certificate Thumbprint

In PowerShell, use GetCertHashString() method associated with ServicePoint.Certificate to get SSL certificate thumbprint or cert hash value.

Thumbprint or certificate hash is a unique identifier to identify the digital certificate.

In this article, we will discuss how to find the SSL certificate thumbprint or hash value in PowerShell.

Find SSL Certificate Thumbprint of a Website in PowerShell

In PowerShell, use the [Net.HttpWebRequest] library to create a connection to the website URI. It retrieves all the information about URI.

Run the following PowerShell script to get the SSL certificate details and retrieve the SSL certificate thumbprint of a website.

# Ignore SSL Warning
[Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }

# Create Web Http request to URI
$uri = "https://google.com/" 
$webRequest = [Net.HttpWebRequest]::Create($uri)

# Get
$webRequest.ServicePoint

# Retrieve the Information for URI
$webRequest.GetResponse() | Out-NULL

# Get SSL Certificate and its details
$webRequest.ServicePoint.Certificate

# Get SSL Certificate Thumbprint
$webRequest.ServicePoint.Certificate.GetCertHashString()

In the above PowerShell script, it uses [Net.HttpWebRequest] to create HTTP web requests to website URI and retrieve the URI properties like Address, ConnectionName, Certificate, etc… in the $webRequest variable.

$webRequest.GetResponse() retrieves the response for the URI and fetches certificate details, Server, Headers, and other relevant information.

$webRequest.ServicePoint.Certificate retrieves the SSL certificate details. Use GetCertHashString() method to get the SSL certificate thumbprint or cert hash string value.

The output of the above PowerShell script to obtain the SSL certificate hash of a website is:

PowerShell Get SSL Certificate Thumbprint
PowerShell Get SSL Certificate Thumbprint

Cool Tip: How to check SSL certificate expiration date in PowerShell!

Conclusion

I hope the above article on how to find the SSL certificate thumbprint of a website in PowerShell is helpful to you.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.