Skip to content

Instantly share code, notes, and snippets.

@pudquick
Forked from lamw/Get-SSLThumbprint.ps1
Created May 22, 2016 15:07
Show Gist options
  • Save pudquick/e7972af800e9a8350f2e044aa8c72698 to your computer and use it in GitHub Desktop.
Save pudquick/e7972af800e9a8350f2e044aa8c72698 to your computer and use it in GitHub Desktop.
Powershell snippet to help extract the SSL Thumbprint (SHA1) of a remote system
Function Get-SSLThumbprint {
param(
[Parameter(
Position=0,
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)
]
[Alias('FullName')]
[String]$URL
)
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class IDontCarePolicy : ICertificatePolicy {
public IDontCarePolicy() {}
public bool CheckValidationResult(
ServicePoint sPoint, X509Certificate cert,
WebRequest wRequest, int certProb) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = new-object IDontCarePolicy
# Need to connect using simple GET operation for this to work
Invoke-RestMethod -Uri $URL -Method Get | Out-Null
$ENDPOINT_REQUEST = [System.Net.Webrequest]::Create("$URL")
$SSL_THUMBPRINT = $ENDPOINT_REQUEST.ServicePoint.Certificate.GetCertHashString()
return $SSL_THUMBPRINT -replace '(..(?!$))','$1:'
}
# vCenter Server URL
$vcurl = "https://vcenter60-1.primp-industries.com"
# Example output
Get-SSLThumbprint $vcurl
17:96:3C:50:25:C5:7E:30:1A:22:A1:B7:8D:97:39:4E:F4:F3:6A:DE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment