Skip to content

Instantly share code, notes, and snippets.

@xixi773
xixi773 / Download-CertificateFromKeyVaultSample.ps1
Created February 1, 2022 07:56
[Error] MethodInvocationException: Exception calling "Import" with "3" argument(s): "X509Certificate is immutable on this platform. Use the equivalent constructor instead."
# Code sample from: https://docs.microsoft.com/en-us/powershell/module/az.keyvault/get-azkeyvaultcertificate?view=azps-4.6.1#example-2--get-cert-and-save-it-as-pfx
# Accessed 9/10/2020
$cert = Get-AzKeyVaultCertificate -VaultName "ContosoKV01" -Name "TestCert01"
$secret = Get-AzKeyVaultSecret -VaultName $vaultName -Name $cert.Name
$secretByte = [Convert]::FromBase64String($secret.SecretValueText)
# This will fail with the following error in PowerShell Core:
# MethodInvocationException: Exception calling "Import" with "3" argument(s): "X509Certificate is immutable on this platform. Use the equivalent constructor instead."