Skip to content

Instantly share code, notes, and snippets.

@davidroberts63
Created July 5, 2022 14:18
Show Gist options
  • Save davidroberts63/93195dcc8f8abe4b8390e9e74cb5d37d to your computer and use it in GitHub Desktop.
Save davidroberts63/93195dcc8f8abe4b8390e9e74cb5d37d to your computer and use it in GitHub Desktop.
Gets the most recent thumbprint of a TLS certificate on a Windows host for use within Octopus Deploy processes.
function FindTlsThumbprintToUse
{
param(
[String]$VariableName = "TlsThumbprint"
)
$thumbprint = Get-ChildItem -Path cert:\LocalMachine\My\* -EKU "Server Authentication" |
Where-Object {
# The last where, for -eq $true helps avoid returning a null object in some cases.
$_.DnsNameList -and ($_.DnsNameList.punycode.endswith(".yourtlddomain.here") | Where-Object { $_ -eq $true })
} |
Sort-Object notbefore -desc |
Select-Object -Last 1 -ExpandProperty thumbprint
if ($thumbprint) {
Set-OctopusVariable -name $VariableName -value $thumbprint
Write-Host "Setting variable named $variableName with the thumbprint of $thumbprint"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment