forked from OCram85/PSCredentialStore
Publish preview version (#42)
* adds certificate store location * add additional certificate store tests * add cert store tests for New-CredentialStoreItem * fix test * add error handling for credential store path * add Import-CSCertificate helper function * Import new certificate if param is given * fix extension filter * add linux error message * fix pester test for linux * update cert helper functions * export helper functions * fix cs cert import * simplify cs cret lookup * remove obsolete functions * fix pester test for linux * fix error type for linux * fix var name * fix pester test * disable travis artifact upload * update cert lookup for item functions * debug build error * use cert instance constructor for linux * disable debug output * remove obsolete exports
This commit is contained in:
86
src/Certificate/Test-CSCertificate.ps1
Normal file
86
src/Certificate/Test-CSCertificate.ps1
Normal file
@ -0,0 +1,86 @@
|
||||
function Test-CSCertificate {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Tests if the given certificate exists in a store.
|
||||
|
||||
.DESCRIPTION
|
||||
Use this function to ensure if a certificate is already imported into a given store.
|
||||
|
||||
.PARAMETER Thumbprint
|
||||
Provide one or more thumprints.
|
||||
|
||||
.PARAMETER StoreName
|
||||
Select the store name in which you want to search the certificates.
|
||||
|
||||
.PARAMETER StoreLocation
|
||||
Select between the both available locations CurrentUser odr LocalMachine.
|
||||
|
||||
.INPUTS
|
||||
[None]
|
||||
|
||||
.OUTPUTS
|
||||
[bool]
|
||||
|
||||
.EXAMPLE
|
||||
Test-CSCertificate -Thumbprint '12345678' -StoreName 'My' -StoreLocation 'CurrentUser'
|
||||
|
||||
.NOTES
|
||||
File Name : Test-CSCertificate.ps1
|
||||
Author : Marco Blessing - marco.blessing@googlemail.com
|
||||
Requires :
|
||||
|
||||
.LINK
|
||||
https://github.com/OCram85/PSCredentialStore
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
[OutputType([bool])]
|
||||
param(
|
||||
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$Thumbprint,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[ValidateSet(
|
||||
'AddressBook',
|
||||
'AuthRoot',
|
||||
'CertificateAuthority',
|
||||
'Disallowed',
|
||||
'My',
|
||||
'Root',
|
||||
'TrustedPeople',
|
||||
'TrustedPublisher'
|
||||
)]
|
||||
[string]$StoreName = 'My',
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[ValidateSet(
|
||||
'CurrentUser',
|
||||
'LocalMachine'
|
||||
)]
|
||||
[string]$StoreLocation = 'CurrentUser'
|
||||
)
|
||||
|
||||
begin {
|
||||
$Store = [System.Security.Cryptography.X509Certificates.X509Store]::New($StoreName, $StoreLocation)
|
||||
try {
|
||||
$Store.Open('ReadOnly')
|
||||
}
|
||||
catch {
|
||||
$_.Exception.Message | Write-Error -ErrorAction Stop
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
$Cert = $Store.Certificates | Where-Object { $_.Thumbprint -eq $Thumbprint }
|
||||
|
||||
if ($null -eq $Cert) {
|
||||
return $false
|
||||
}
|
||||
else {
|
||||
return $true
|
||||
}
|
||||
}
|
||||
end {
|
||||
$Store.Close()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user