adds certificate store location
This commit is contained in:
parent
5a68527061
commit
858dfde937
@ -87,7 +87,26 @@ function Get-CredentialStoreItem {
|
||||
$CSMembers = Get-Member -InputObject $CS
|
||||
# Let's first check if the given remote host exists as object property
|
||||
if (($CSMembers.MemberType -eq "NoteProperty") -and ($CSMembers.Name -contains $CredentialName)) {
|
||||
$Cert = Get-PfxCertificate -FilePath $CS.PfXCertificate -ErrorAction Stop
|
||||
try {
|
||||
if ($null -eq $CS.PfxCertificate) {
|
||||
$Cert = Get-ChildItem -Recurse -Path 'Cert:' | Where-Object {
|
||||
$_.Thumbprint -eq $CS.Thumbprint
|
||||
} | Select-Object -First 1
|
||||
}
|
||||
else {
|
||||
$Cert = Get-PfxCertificate -FilePath $CS.PfxCertificate -ErrorAction Stop
|
||||
}
|
||||
}
|
||||
catch {
|
||||
$_.Exception.Message | Write-Error
|
||||
$ErrorParams = @{
|
||||
ErrorAction = 'Stop'
|
||||
Exception = [System.Security.Cryptography.CryptographicException]::new(
|
||||
'Could not read the given PFX certificate.'
|
||||
)
|
||||
}
|
||||
Write-Error @ErrorParams
|
||||
}
|
||||
$DecryptedKey = $Cert.PrivateKey.Decrypt(
|
||||
[Convert]::FromBase64String($CS.$CredentialName.EncryptedKey),
|
||||
[System.Security.Cryptography.RSAEncryptionPadding]::Pkcs1
|
||||
|
@ -117,7 +117,14 @@ function New-CredentialStoreItem {
|
||||
|
||||
if ($Credential.UserName) {
|
||||
try {
|
||||
$Cert = Get-PfxCertificate -FilePath $CSContent.PfxCertificate -ErrorAction Stop
|
||||
if ($null -eq $CSContent.PfxCertificate) {
|
||||
$Cert = Get-ChildItem -Recurse -Path 'Cert:' | Where-Object {
|
||||
$_.Thumbprint -eq $CSContent.Thumbprint
|
||||
} | Select-Object -First 1
|
||||
}
|
||||
else {
|
||||
$Cert = Get-PfxCertificate -FilePath $CSContent.PfxCertificate -ErrorAction Stop
|
||||
}
|
||||
}
|
||||
catch {
|
||||
$_.Exception.Message | Write-Error
|
||||
|
@ -103,14 +103,22 @@ function Set-CredentialStoreItem {
|
||||
|
||||
if ($Credential.UserName) {
|
||||
try {
|
||||
$Cert = Get-PfxCertificate -FilePath $CSContent.PfxCertificate -ErrorAction Stop
|
||||
if ($null -eq $CSContent.PfxCertificate) {
|
||||
$Cert = Get-ChildItem -Recurse -Path 'Cert:' | Where-Object {
|
||||
$_.Thumbprint -eq $CSContent.Thumbprint
|
||||
} | Select-Object -First 1
|
||||
}
|
||||
else {
|
||||
$Cert = Get-PfxCertificate -FilePath $CSContent.PfxCertificate -ErrorAction Stop
|
||||
}
|
||||
}
|
||||
catch {
|
||||
$_.Exception.Message | Write-Error
|
||||
$ErrorParams = @{
|
||||
Message = 'Could not read the given PFX certificate.'
|
||||
ErrorAction = 'Stop'
|
||||
Exception = [System.Security.Cryptography.CryptographicException]::new()
|
||||
Exception = [System.Security.Cryptography.CryptographicException]::new(
|
||||
'Could not read the given PFX certificate.'
|
||||
)
|
||||
}
|
||||
Write-Error @ErrorParams
|
||||
}
|
||||
|
@ -63,15 +63,19 @@ function New-CredentialStore {
|
||||
|
||||
[Parameter(Mandatory = $false, ParameterSetName = "Private")]
|
||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
||||
[switch]$Force,
|
||||
[Switch]$Force,
|
||||
|
||||
[Parameter(Mandatory = $false, ParameterSetName = "Private")]
|
||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
||||
[switch]$PassThru,
|
||||
[Switch]$PassThru,
|
||||
|
||||
[Parameter(Mandatory = $false, ParameterSetName = "Private")]
|
||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
||||
[Switch]$SkipPFXCertCreation
|
||||
[Switch]$SkipPFXCertCreation,
|
||||
|
||||
[Parameter(Mandatory = $false, ParameterSetName = "Private")]
|
||||
[Parameter(Mandatory = $false, ParameterSetName = "Shared")]
|
||||
[Switch]$UseCertStore
|
||||
)
|
||||
|
||||
begin {
|
||||
@ -112,8 +116,8 @@ function New-CredentialStore {
|
||||
State = 'PSCredentialStore'
|
||||
City = 'PSCredentialStore'
|
||||
Organization = 'PSCredentialStore'
|
||||
OrganizationalUnitName = ' '
|
||||
CommonName = 'PrivateStore'
|
||||
OrganizationalUnitName = $PSCmdlet.ParameterSetName
|
||||
CommonName = 'PSCredentialStore'
|
||||
}
|
||||
$CRTAttribute = New-CRTAttribute @CRTParams
|
||||
|
||||
@ -176,8 +180,14 @@ function New-CredentialStore {
|
||||
Type = $null
|
||||
}
|
||||
if (! $SkipPFXCertCreation.IsPresent) {
|
||||
$ObjProperties.PfXCertificate = $PfxParams.CertName
|
||||
$ObjProperties.Thumbprint = $FreshCert.Thumbprint
|
||||
|
||||
if (!$UseCertStore.IsPresent) {
|
||||
$ObjProperties.PfxCertificate = $PfxParams.CertName
|
||||
}
|
||||
else {
|
||||
Write-Warning -Message ("New certificate {0} created. Please import it into your certificate store manually!" -f $PfxParams.CertName)
|
||||
}
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ParameterSetName -eq "Shared") {
|
||||
|
Loading…
Reference in New Issue
Block a user