Last active
June 13, 2017 15:02
-
-
Save lantrix/76093b0be6a8a6f3dd19 to your computer and use it in GitHub Desktop.
Powershell Check Cert Expiry Days
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
| #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