Created
July 5, 2022 14:18
-
-
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.
This file contains hidden or 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
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