2019-04-04 17:02:17 +02:00
|
|
|
function Test-CSCertificate {
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
2019-04-29 16:05:43 +02:00
|
|
|
Tests if the linked certificate is store ein the specified cert stores.
|
2019-04-04 17:02:17 +02:00
|
|
|
|
|
|
|
.DESCRIPTION
|
2019-04-29 16:05:43 +02:00
|
|
|
Test-CSCertificate should be an easy high level test for the linked certificate.
|
2019-04-04 17:02:17 +02:00
|
|
|
|
2019-04-29 16:05:43 +02:00
|
|
|
.PARAMETER Type
|
|
|
|
Select between 'Private' or 'Shared'.
|
2019-04-04 17:02:17 +02:00
|
|
|
|
|
|
|
.INPUTS
|
|
|
|
[None]
|
|
|
|
|
|
|
|
.OUTPUTS
|
|
|
|
[bool]
|
|
|
|
|
|
|
|
.EXAMPLE
|
2019-04-29 16:05:43 +02:00
|
|
|
Test-CSCertificate -Type 'Shared'
|
2019-04-04 17:02:17 +02:00
|
|
|
|
|
|
|
.NOTES
|
2019-04-29 16:05:43 +02:00
|
|
|
- File Name : Test-CSCertificate.ps1
|
|
|
|
- Author : Marco Blessing - marco.blessing@googlemail.com
|
|
|
|
- Requires :
|
2019-04-04 17:02:17 +02:00
|
|
|
|
|
|
|
.LINK
|
|
|
|
https://github.com/OCram85/PSCredentialStore
|
|
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
|
|
[OutputType([bool])]
|
|
|
|
param(
|
2019-04-29 16:05:43 +02:00
|
|
|
[Parameter(Mandatory = $true)]
|
2019-04-04 17:02:17 +02:00
|
|
|
[ValidateNotNullOrEmpty()]
|
2019-04-29 16:05:43 +02:00
|
|
|
[ValidateSet('Private', 'Shared')]
|
|
|
|
[string]$Type
|
2019-04-04 17:02:17 +02:00
|
|
|
)
|
|
|
|
begin {
|
2019-04-29 16:05:43 +02:00
|
|
|
if ($Type -eq 'Private') {
|
|
|
|
$CS = Get-CredentialStore
|
2019-04-04 17:02:17 +02:00
|
|
|
}
|
2019-04-29 16:05:43 +02:00
|
|
|
elseif ($Type -eq 'Shared') {
|
|
|
|
$CS = Get-CredentialStore -Shared
|
|
|
|
}
|
|
|
|
if ($null -ne $CS.PfxCertificate) {
|
|
|
|
Write-Warning 'There is a Pfx certificate file linked in the store. Certificates saved in the Cert store will be ignored!'
|
2019-04-04 17:02:17 +02:00
|
|
|
}
|
|
|
|
|
2019-04-29 16:05:43 +02:00
|
|
|
}
|
2019-04-04 17:02:17 +02:00
|
|
|
process {
|
2019-04-29 16:05:43 +02:00
|
|
|
if ($Type -eq 'Private') {
|
|
|
|
$cert = Get-CSPfXCertificate -Thumbprint $CS.Thumbprint -StoreName 'My' -StoreLocation 'CurrentUser'
|
|
|
|
}
|
|
|
|
elseif ($Type -eq 'Shared') {
|
|
|
|
if ( $isLinux) {
|
|
|
|
$cert = Get-CSPfxCertificate -Thumbprint $CS.Thumbprint -StoreName 'My' -StoreLocation 'CurrentUser'
|
|
|
|
if ($null -eq $cert) {
|
|
|
|
$cert = Get-CSPfxCertificate -Thumbprint $CS.Thumbprint -StoreName 'Root' -StoreLocation 'LocalMachine'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif ( (! $isLinux) -or ($isWindows) ) {
|
|
|
|
$cert = Get-CSPfxCertificate -Thumbprint $CS.Thumbprint -StoreName 'My' -StoreLocation 'LocalMachine'
|
|
|
|
if ($null -eq $cert) {
|
|
|
|
$cert = Get-CSPfxCertificate -Thumbprint $CS.Thumbprint -StoreName 'Root' -StoreLocation 'LocalMachine'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($null -eq $cert) {
|
2019-04-04 17:02:17 +02:00
|
|
|
return $false
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return $true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end {
|
|
|
|
}
|
|
|
|
}
|