Marco Blessing
7708df9b66
* update pwsh style in store files * update pwsh style in item files * update pwsh style in connection files * update pwsh style in certificate files * update pwsh style in private files * update pwsh style in drone helper * update meta * fix pwsh style * fix output type * fix typo in OutputType * update appveyor build mode * debugging build mode * wip * test windows pipeline * fix typo * simplify drone setup * update readme * remove deprecated cicd setup * update pwsh style
67 lines
2.0 KiB
PowerShell
67 lines
2.0 KiB
PowerShell
function Get-CSCertificate {
|
|
<#
|
|
.SYNOPSIS
|
|
Returns the current used valid PfX certificate.
|
|
|
|
.DESCRIPTION
|
|
Use this function to get the available pfx certificate respecting the config hierarchy.
|
|
|
|
.PARAMETER Type
|
|
Select the current credential store type.
|
|
|
|
.PARAMETER Thumbprint
|
|
Provide the credentials thumbprint for the search.
|
|
|
|
.INPUTS
|
|
[None]
|
|
|
|
.OUTPUTS
|
|
[System.Security.Cryptography.X509Certificates.X509Certificate2]
|
|
|
|
.EXAMPLE
|
|
Get-CSCertificate -Type 'Shared' -Thumbprint '12334456'
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
[OutputType([System.Security.Cryptography.X509Certificates.X509Certificate2])]
|
|
param (
|
|
[Parameter(Mandatory = $true)]
|
|
[ValidateNotNullOrEmpty()]
|
|
[ValidateSet('Private', 'Shared')]
|
|
[string]$Type,
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
[ValidateNotNullOrEmpty()]
|
|
[string]$Thumbprint
|
|
)
|
|
|
|
begin {}
|
|
|
|
process {
|
|
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
|
|
}
|
|
}
|
|
}
|
|
}
|
|
end {}
|
|
}
|