Powershell "X509Certificate2Collection" Exception calling "Import" with "3" argument(s): "Cannot find the requested object Powershell "X509Certificate2Collection" Exception calling "Import" with "3" argument(s): "Cannot find the requested object powershell powershell

Powershell "X509Certificate2Collection" Exception calling "Import" with "3" argument(s): "Cannot find the requested object


Change the code like this and you are good to go!

    $secretName = "TestCert"    $kvSecret = Get-AzureKeyVaultSecret -VaultName $vaultName -Name $certificateName    $kvSecretBytes = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($kvSecret.SecretValueText))    $jsonCert = ConvertFrom-Json($kvSecretBytes)    $certBytes = [System.Convert]::FromBase64String($jsonCert.data)    $certCollection = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2Collection    $certCollection.Import($certBytes,$jsonCert.password,[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)