Public/Get-ExpiredCertificate.ps1

function Get-ExpiredCertificate {
    <#
    .SYNOPSIS
        Gets expired certificates.
    .DESCRIPTION
        This function gets expired certificates from the specified store.
    .PARAMETER CertificateStore
        The certificate store to search. If not specified, all stores will be searched.
    .INPUTS
        System.String[]
    .OUTPUTS
        System.Management.Automation.PSCustomObject[]
    .EXAMPLE
        Get-ExpiredCertificate

        Gets expired certificates from all stores.
    .EXAMPLE
        Get-ExpiredCertificate -CertificateStore My

        Gets expired certificates from the My store.
    .NOTES
        None
    #>


    [CmdletBinding()]
    [OutputType([System.Management.Automation.PSCustomObject])]
    [Alias("gec")]

    param (
        [Parameter(Mandatory = $false, ValueFromPipeline = $false)]
        [ValidateSet("All", "My", "Root", "CA", "TrustedPublisher", "AuthRoot")]
        [string[]]$CertificateStore
    )

    begin {
        if ( -not $CertificateStore -or $CertificateStore -eq "All" ) {
            $stores = @("My", "Root", "CA", "TrustedPublisher", "AuthRoot")
        }
        else {
            $stores = $CertificateStore
        }
    }

    process {
        foreach ($store in $stores) {
            Get-ChildItem -Path "Cert:\LocalMachine\$store" |
            Where-Object { $_.NotAfter -lt (Get-Date) } |
            Select-Object Subject, Issuer, NotBefore, NotAfter, Thumbprint
        }
    }

    end {}
}