From 4d034683c3917b491d50902f5cc2883af82d5534 Mon Sep 17 00:00:00 2001 From: Andrew Dawson <62777308+dawsonar802@users.noreply.github.com> Date: Fri, 20 Nov 2020 11:31:04 -0500 Subject: [PATCH 1/2] Update Get-AzKeyVaultCertificate.md The existing syntax does not seem to work in PowerShell Core. Using the proposed syntax works with both PowerShell Desktop and Core. When Calling the 'import' in this line: $x509Cert.Import($secretByte, "", "Exportable,PersistKeySet") in PowerShell core, an error is received "Import" with "3" argument(s): "X509Certificate is immutable on this platform. Use the equivalent constructor instead." Declaring the cert object like this works fine: $x509Cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($secretByte, "", "Exportable,PersistKeySet") The recommended change is a combination of the existing MS Documentation and the above which was pulled from: https://gist.github.com/holgerjay/0db1f759f93cba268d671341b787472a --- src/KeyVault/KeyVault/help/Get-AzKeyVaultCertificate.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/KeyVault/KeyVault/help/Get-AzKeyVaultCertificate.md b/src/KeyVault/KeyVault/help/Get-AzKeyVaultCertificate.md index 66b4a6f73539..8dabff1b440b 100644 --- a/src/KeyVault/KeyVault/help/Get-AzKeyVaultCertificate.md +++ b/src/KeyVault/KeyVault/help/Get-AzKeyVaultCertificate.md @@ -117,10 +117,10 @@ try { [System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($ssPtr) } $secretByte = [Convert]::FromBase64String($secretValueText) -$x509Cert = new-object System.Security.Cryptography.X509Certificates.X509Certificate2 -$x509Cert.Import($secretByte, "", "Exportable,PersistKeySet") +$x509Cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($secretByte, "", "Exportable,PersistKeySet") $type = [System.Security.Cryptography.X509Certificates.X509ContentType]::Pfx $pfxFileByte = $x509Cert.Export($type, $password) +$pfxFileByte = $x509Cert.Export($type, $password) # Write to a file [System.IO.File]::WriteAllBytes("KeyVault.pfx", $pfxFileByte) From fe48eb8f58d50eabe6a9cdc7d34156b7f922d86e Mon Sep 17 00:00:00 2001 From: Yeming Liu Date: Tue, 24 Nov 2020 11:24:59 +0800 Subject: [PATCH 2/2] Remove duplicated line in example --- src/KeyVault/KeyVault/help/Get-AzKeyVaultCertificate.md | 1 - 1 file changed, 1 deletion(-) diff --git a/src/KeyVault/KeyVault/help/Get-AzKeyVaultCertificate.md b/src/KeyVault/KeyVault/help/Get-AzKeyVaultCertificate.md index 8dabff1b440b..5943c608ec91 100644 --- a/src/KeyVault/KeyVault/help/Get-AzKeyVaultCertificate.md +++ b/src/KeyVault/KeyVault/help/Get-AzKeyVaultCertificate.md @@ -120,7 +120,6 @@ $secretByte = [Convert]::FromBase64String($secretValueText) $x509Cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($secretByte, "", "Exportable,PersistKeySet") $type = [System.Security.Cryptography.X509Certificates.X509ContentType]::Pfx $pfxFileByte = $x509Cert.Export($type, $password) -$pfxFileByte = $x509Cert.Export($type, $password) # Write to a file [System.IO.File]::WriteAllBytes("KeyVault.pfx", $pfxFileByte)