Skip to content

Instantly share code, notes, and snippets.

@lantrix
Last active June 13, 2017 15:02
Show Gist options
  • Select an option

  • Save lantrix/76093b0be6a8a6f3dd19 to your computer and use it in GitHub Desktop.

Select an option

Save lantrix/76093b0be6a8a6f3dd19 to your computer and use it in GitHub Desktop.
Powershell Check Cert Expiry Days
#requires -Version 3
<#
.SYNOPSIS
Search Servers for a certificate and show expiry date
.EXAMPLE
Get-CertificateExpirations.ps1 -Servers @("serverA.local","serverB.local") -CertName test.com.au
#>
param(
[Parameter(Mandatory=$true,HelpMessage='Certificate Name')][string]$CertName,
[array]$Servers=@(
'server1.local',
'server2.local'
)
)
$command = { param([Parameter(Mandatory=$true)]$cert) Get-ChildItem -Path cert:\localmachine\my | Where-Object {$_.Subject -like "*=$cert*"} | Select-Object -Property subject,notafter }
foreach ($s in $Servers) {
Write-Verbose -Message "running check on $s"
Invoke-Command -ComputerName $s -ScriptBlock $command -ArgumentList $CertName
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment