Public/Get-Certificates.ps1

Function Get-Certificates {
    <#
.SYNOPSIS
    This Function lists Certificates
.NOTES
    Name: Get-Certificates
    Author: Luke Hagar
    Version: 1.0
    DateCreated: 2020-Jan-10
.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 { }
}