2019-04-04 17:02:17 +02:00
|
|
|
function Import-CSCertificate {
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
2019-04-29 16:05:43 +02:00
|
|
|
Imports a linked certificate to the valid store location.
|
2019-04-04 17:02:17 +02:00
|
|
|
|
|
|
|
.DESCRIPTION
|
2019-04-29 16:05:43 +02:00
|
|
|
Import-CSCertificate takes a pfx certificate file and imports it to the supposed certificate store for
|
|
|
|
private and shared credential stores.
|
2019-04-04 17:02:17 +02:00
|
|
|
|
2019-04-29 16:05:43 +02:00
|
|
|
.PARAMETER Type
|
|
|
|
Select between the a private and shared credential store.
|
2019-04-04 17:02:17 +02:00
|
|
|
|
2019-04-29 16:05:43 +02:00
|
|
|
.PARAMETER Path
|
|
|
|
Provide a valid path to pfx certificate file.
|
2019-04-04 17:02:17 +02:00
|
|
|
|
|
|
|
.INPUTS
|
|
|
|
[None]
|
|
|
|
|
|
|
|
.OUTPUTS
|
|
|
|
[None]
|
|
|
|
|
|
|
|
.EXAMPLE
|
2019-04-29 16:05:43 +02:00
|
|
|
Import-CSCertificate -Type 'Private' -Path (Join-Path -Path $Env:APPDATA -ChildItem 'PfxCertificate.pfx')
|
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()]
|
2022-06-28 08:56:33 +02:00
|
|
|
param (
|
2019-04-04 17:02:17 +02:00
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
[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()]
|
|
|
|
[System.IO.FileInfo]$Path
|
2019-04-04 17:02:17 +02:00
|
|
|
|
|
|
|
)
|
|
|
|
begin {
|
2019-04-29 16:05:43 +02:00
|
|
|
if (! (Test-Path -Path $Path)) {
|
2019-04-04 17:02:17 +02:00
|
|
|
$ErrorParams = @{
|
|
|
|
ErrorAction = 'Stop'
|
|
|
|
Exception = [System.Exception]::new(
|
2019-04-29 16:05:43 +02:00
|
|
|
('File {0} not found!') -f $Path
|
2019-04-04 17:02:17 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
Write-Error @ErrorParams
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 16:05:43 +02:00
|
|
|
|
|
|
|
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'
|
|
|
|
}
|
|
|
|
}
|
2019-04-04 17:02:17 +02:00
|
|
|
end {
|
|
|
|
}
|
|
|
|
}
|