Я пытаюсь получить отпечаток, защищенный паролем файл PFX, используя этот код:PowerShell Получить сертификат Отпечаток с паролем PFX Файл
function Get-CertificateThumbprint {
#
# This will return a certificate thumbprint, null if the file isn't found or throw an exception.
#
param (
[parameter(Mandatory = $true)][string] $CertificatePath,
[parameter(Mandatory = $false)][string] $CertificatePassword
)
try {
if (!(Test-Path $CertificatePath)) {
return $null;
}
if ($CertificatePassword) {
$sSecStrPassword = ConvertTo-SecureString -String $CertificatePassword -Force –AsPlainText
}
$certificateObject = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$certificateObject.Import($CertificatePath, $sSecStrPassword);
return $certificateObject.Thumbprint
} catch [Exception] {
#
# Catch accounts already added.
throw $_;
}
}
Когда я бегу, я получаю эту ошибку:
Cannot find an overload for "Import" and the argument count: "2".
At C:\temp\test.ps1:36 char:9
+ $certificateObject.Import($CertificatePath, $sSecStrPassword);
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
Может кто-нибудь, пожалуйста, помогите мне разобраться с этим?
Спасибо всем. :-)
Пример от Microsoft: PS C: \> Get- PfxCertificate -FilePath "C: \ windows \ system32 \ Test.pfx" – niklasolsn
Get-PfxCertificate не имеет пароля. См. Ответ kyorilys, если вам нужно импортировать сертификат в неинтерактивный режим. –