Public/Get-Certificates.ps1
Function Get-Certificates { <# .SYNOPSIS This Function lists Certificates from a remote host .NOTES Name: Get-Certificates Author: Luke Hagar Version: 1.0 DateCreated: 5/12/2021 .Parameter ComputerName [string[]]$ComputerName = $env:COMPUTERNAME Hostname to run commands against .Parameter Threshold [double]$Threshold = 30 Number of days forard to search for expiring certificates .EXAMPLE Get-Certificates -ComputerName Hostname1 .LINK #> [CmdletBinding()] param ( [Parameter( ValueFromPipeline, ValueFromPipelineByPropertyName )] [Alias('dnsHostName')] [string[]]$ComputerName = $env:COMPUTERNAME, [double]$Threshold = 30 ) BEGIN { $Deadline = (Get-Date).AddDays($Threshold) } PROCESS { Foreach ($Computer in $ComputerName) { If ($Computer -eq $env:COMPUTERNAME) { Get-ChildItem Cert:\LocalMachine\My | ForEach-Object { If ($_.NotAfter -le $deadline) { $_ | Select-Object Issuer, Subject, NotAfter, @{ Label = "Expires In (Days)" Expression = { ($_.NotAfter - (Get-Date)).Days } } } } } else { Invoke-Command -ComputerName $Computer { Get-ChildItem Cert:\LocalMachine\My } | ForEach-Object { If ($_.NotAfter -le $deadline) { $_ | Select-Object Issuer, Subject, NotAfter, @{ Label = "Expires In (Days)" Expression = { ($_.NotAfter - (Get-Date)).Days } } } } } } } END { } } |