forked from OCram85/PSCredentialStore
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
65 lines
1.9 KiB
PowerShell
65 lines
1.9 KiB
PowerShell
function Import-CSCertificate {
|
|
<#
|
|
.SYNOPSIS
|
|
Imports a linked certificate to the valid store location.
|
|
|
|
.DESCRIPTION
|
|
Import-CSCertificate takes a pfx certificate file and imports it to the supposed certificate store for
|
|
private and shared credential stores.
|
|
|
|
.PARAMETER Type
|
|
Select between the a private and shared credential store.
|
|
|
|
.PARAMETER Path
|
|
Provide a valid path to pfx certificate file.
|
|
|
|
.INPUTS
|
|
[None]
|
|
|
|
.OUTPUTS
|
|
[None]
|
|
|
|
.EXAMPLE
|
|
Import-CSCertificate -Type 'Private' -Path (Join-Path -Path $Env:APPDATA -ChildItem 'PfxCertificate.pfx')
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
param (
|
|
[Parameter(Mandatory = $true)]
|
|
[ValidateNotNullOrEmpty()]
|
|
[ValidateSet('Private', 'Shared')]
|
|
[string]$Type,
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
[ValidateNotNullOrEmpty()]
|
|
[System.IO.FileInfo]$Path
|
|
|
|
)
|
|
begin {
|
|
if (! (Test-Path -Path $Path)) {
|
|
$ErrorParams = @{
|
|
ErrorAction = 'Stop'
|
|
Exception = [System.Exception]::new(
|
|
('File {0} not found!') -f $Path
|
|
)
|
|
}
|
|
Write-Error @ErrorParams
|
|
}
|
|
}
|
|
|
|
process {
|
|
# Import to CurrentUser\My store for windows and linux
|
|
if ($Type -eq 'Private') {
|
|
Import-CSPfxCertificate -Path $Path -StoreName 'My' -StoreLocation 'CurrentUser' -OpenFlags 'ReadWrite'
|
|
}
|
|
elseif ( (! $isLinux ) -and ($Type -eq 'Shared') ) {
|
|
Import-CSPfxCertificate -Path $Path -StoreName 'My' -StoreLocation 'LocalMachine' -OpenFlags 'ReadWrite'
|
|
}
|
|
elseif ( ($isLinux) -and ($Type -eq 'Shared') ) {
|
|
Import-CSPfxCertificate -Path $Path -StoreName 'My' -StoreLocation 'CurrentUser' -OpenFlags 'ReadWrite'
|
|
}
|
|
}
|
|
end {
|
|
}
|
|
}
|