Skip to content

Commit 3a197cb

Browse files
Update Get-AzKeyVaultCertificate.md - Get cert and save it as pfx section to work with PowerShell Core (#13557)
* 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 * Remove duplicated line in example Co-authored-by: Yeming Liu <[email protected]>
1 parent 629cff0 commit 3a197cb

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/KeyVault/KeyVault/help/Get-AzKeyVaultCertificate.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ try {
117117
[System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($ssPtr)
118118
}
119119
$secretByte = [Convert]::FromBase64String($secretValueText)
120-
$x509Cert = new-object System.Security.Cryptography.X509Certificates.X509Certificate2
121-
$x509Cert.Import($secretByte, "", "Exportable,PersistKeySet")
120+
$x509Cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($secretByte, "", "Exportable,PersistKeySet")
122121
$type = [System.Security.Cryptography.X509Certificates.X509ContentType]::Pfx
123122
$pfxFileByte = $x509Cert.Export($type, $password)
124123

0 commit comments

Comments
 (0)