Closed
Description
Description
I am trying to import a .p12 certificate to Azure Key Vault but am getting an error.
Import-AzKeyVaultCertificate: Key not valid for use in specified state.
Some links online indicate a password may be required to import the certificate, but the certificate does not have one and our equivalent Azure CLI command does not pass a password either.
Issue script & Debug output
PS > Import-AzKeyVaultCertificate -FilePath .\$FileName.p12 -Name $CertificateName -VaultName $VaultName
DEBUG: 10:22:50 AM - ImportAzureKeyVaultCertificate begin processing with ParameterSet 'ImportCertificateFromFile'.
DEBUG: 10:22:50 AM - using account id '<REDACTED>'...
Import-AzKeyVaultCertificate: Key not valid for use in specified state.
DEBUG: AzureQoSEvent: CommandName - Import-AzKeyVaultCertificate; IsSuccess - False; Duration - 00:00:00.3343187; Exception - Key not valid for use in specified state.;
DEBUG: Finish sending metric.
DEBUG: 10:22:52 AM - ImportAzureKeyVaultCertificate end processing.
Environment data
PS > $PSVersionTable
Name Value
---- -----
PSVersion 7.1.3
PSEdition Core
GitCommitId 7.1.3
OS Microsoft Windows 10.0.19043
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Module versions
PS > Get-Module Az*
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 2.3.0 Az.Accounts {Add-AzEnvironment, Clear-AzContext, Clear-AzDefault, Connect-…
Script 3.4.4 Az.KeyVault {Add-AzKeyVaultCertificate, Add-AzKeyVaultCertificateContact, …
Error output
PS > Resolve-AzError
DEBUG: 10:30:54 AM - ResolveError begin processing with ParameterSet 'AnyErrorParameterSet'.
DEBUG: 10:30:54 AM - using account id '<REDACTED>'...
WARNING: Upcoming breaking changes in the cmdlet 'Resolve-AzError' :
The `Resolve-Error` alias will be removed in a future release. Please change any scripts that use this alias to use `Resolve-AzError` instead.
Note : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other information on breaking changes in Azure PowerShell.
HistoryId: 27
ErrorCategory : CloseError: (:) [Import-AzKeyVaultCertificate], WindowsCryptographicException
ErrorDetail :
InvocationInfo : {Import-AzKeyVaultCertificate}
Line : Import-AzKeyVaultCertificate -FilePath "$Filename.p12" -Name
$CertificateName -VaultName $VaultName
Position : At line:1 char:1
+ Import-AzKeyVaultCertificate -FilePath "<REDACTED> …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BoundParameters : {}
UnboundParameters :
HistoryId : 27
Resolve-AzError: Collection was modified; enumeration operation may not execute.
DEBUG: AzureQoSEvent: CommandName - Resolve-AzError; IsSuccess - False; Duration - 00:00:00.1092612; Exception - Collection was modified; enumeration operation may not execute.;
DEBUG: Finish sending metric.
DEBUG: 10:30:55 AM - ResolveError end processing.