Skip to content

Instantly share code, notes, and snippets.

@giseongeom
Last active November 29, 2022 07:52
Show Gist options
  • Save giseongeom/735b2d91ffc9fe061c8cc161eda75dd6 to your computer and use it in GitHub Desktop.
Save giseongeom/735b2d91ffc9fe061c8cc161eda75dd6 to your computer and use it in GitHub Desktop.
Check Cert status (openssl)
#Requires -version 5.1
[CmdletBinding()]
Param(
[Parameter(Mandatory = $false)]
[string]$list_file_path = 'list.txt'
)
# Tools
$my_required_tools = @("openssl")
$my_required_tools | ForEach-Object {
if (-not(Get-Command $PSItem -ErrorAction SilentlyContinue)) {
$log_msg = "$PSITEM not found. Exiting...."
Write-Output ''
Write-Output $log_msg
Break
}
}
$today = get-date
$urls = gc $list_file_path
$urls | % {
$target = $_
$target = $target -replace '^http.*\/\/',''
$Expiredate = (echo '' | & openssl.exe s_client -connect ${target}:443 2> $null | openssl x509 -noout -enddate)
$Expiredate = $Expiredate -replace '\s{2,}',' '
#notAfter=Dec 10 23:59:59 2021 GMT
$exp_yr = (($Expiredate -split '=')[1] -split ' ')[3]
$exp_mo = (($Expiredate -split '=')[1] -split ' ')[0]
$exp_day = (($Expiredate -split '=')[1] -split ' ')[1]
$exp_hms = (($Expiredate -split '=')[1] -split ' ')[2]
[datetime]$exp_datetime = $exp_mo + ' ' + $exp_day + ' ' + $exp_yr + ' ' + $exp_hms
$time_days_left = ($exp_datetime - $today).Days
if ($time_days_left -gt 30) { "$target is good. Expires at $exp_datetime" }
if (($time_days_left -gt 0) -and ($time_days_left -le 30)) {
"$target shoud be updated within 30 days. Expires at $exp_datetime"
}
if ($time_days_left -le 0) { "$target is Expired. Renew ASAP" }
}
@giseongeom
Copy link
Author

  • openssl은 Chocolatey 또는 scoop 이용해서 설치하면 편함

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment