2019-04-04 17:02:17 +02:00
|
|
|
function Get-CSCertificate {
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
2019-04-29 16:05:43 +02:00
|
|
|
Returns the current used valid PfX certificate.
|
2019-04-04 17:02:17 +02:00
|
|
|
|
|
|
|
.DESCRIPTION
|
2019-04-29 16:05:43 +02:00
|
|
|
Use this function to get the available pfx certificate respecting the config hierarchy.
|
2019-04-04 17:02:17 +02:00
|
|
|
|
2019-04-29 16:05:43 +02:00
|
|
|
.PARAMETER Type
|
|
|
|
Select the current credential store type.
|
2019-04-04 17:02:17 +02:00
|
|
|
|
2019-04-29 16:05:43 +02:00
|
|
|
.PARAMETER Thumbprint
|
|
|
|
Provide the credentials thumbprint for the search.
|
2019-04-04 17:02:17 +02:00
|
|
|
|
|
|
|
.INPUTS
|
2019-04-29 16:05:43 +02:00
|
|
|
[None]
|
2019-04-04 17:02:17 +02:00
|
|
|
|
|
|
|
.OUTPUTS
|
2019-04-29 16:05:43 +02:00
|
|
|
[System.Security.Cryptography.X509Certificates.X509Certificate2]
|
2019-04-04 17:02:17 +02:00
|
|
|
|
|
|
|
.EXAMPLE
|
2019-04-29 16:05:43 +02:00
|
|
|
Get-CSCertificate -Type 'Shared' -Thumbprint '12334456'
|
2019-04-04 17:02:17 +02:00
|
|
|
#>
|
2022-06-28 08:56:33 +02:00
|
|
|
|
2019-04-04 17:02:17 +02:00
|
|
|
[CmdletBinding()]
|
|
|
|
[OutputType([System.Security.Cryptography.X509Certificates.X509Certificate2])]
|
2022-06-28 08:56:33 +02:00
|
|
|
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
|
|
|
|
2019-04-29 16:05:43 +02:00
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
[ValidateNotNullOrEmpty()]
|
|
|
|
[string]$Thumbprint
|
2019-04-04 17:02:17 +02:00
|
|
|
)
|
|
|
|
|
2022-06-28 08:56:33 +02:00
|
|
|
begin {}
|
|
|
|
|
2019-04-04 17:02:17 +02:00
|
|
|
process {
|
2019-04-29 16:05:43 +02:00
|
|
|
if ($Type -eq 'Private') {
|
|
|
|
Get-CSPfXCertificate -Thumbprint $Thumbprint -StoreName 'My' -StoreLocation 'CurrentUser'
|
|
|
|
}
|
|
|
|
elseif ($Type -eq 'Shared') {
|
|
|
|
if ( $isLinux) {
|
|
|
|
$cert = Get-CSPfxCertificate -Thumbprint $Thumbprint -StoreName 'My' -StoreLocation 'CurrentUser'
|
|
|
|
if ($null -eq $cert) {
|
|
|
|
Get-CSPfxCertificate -Thumbprint $Thumbprint -StoreName 'Root' -StoreLocation 'LocalMachine'
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Write-Output $cert
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif ( (! $isLinux) -or ($isWindows) ) {
|
|
|
|
$cert = Get-CSPfxCertificate -Thumbprint $Thumbprint -StoreName 'My' -StoreLocation 'LocalMachine'
|
|
|
|
if ($null -eq $cert) {
|
|
|
|
Get-CSPfxCertificate -Thumbprint $Thumbprint -StoreName 'Root' -StoreLocation 'LocalMachine'
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Write-Output $cert
|
|
|
|
}
|
|
|
|
}
|
2019-04-04 17:02:17 +02:00
|
|
|
}
|
|
|
|
}
|
2022-06-28 08:56:33 +02:00
|
|
|
end {}
|
2019-04-04 17:02:17 +02:00
|
|
|
}
|