Private/Test-CertInstalled.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function Test-CertInstalled {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory,Position=0,ValueFromPipelineByPropertyName)]
        [Alias('Thumbprint')]
        [string]$CertThumbprint,
        [Parameter(Position=1)]
        [ValidateSet('LocalMachine','CurrentUser')]
        [string]$StoreLocation = 'LocalMachine',
        [Parameter(Position=2)]
        [string]$StoreName = 'My'
    )

    $allCerts = Get-ChildItem Cert:\$StoreLocation\$StoreName

    if ($allCerts | Where-Object {$_.Thumbprint -eq $CertThumbprint}) {
        return $true
    } else {
        return $false
    }

}