Skip to content

Commit 26c148f

Browse files
Fix "save as pfx" example (#19003)
* Fix "save as pfx" example See issue #18251 * Add description for example#1 in `Get-AzKeyVaultCertificate` Co-authored-by: Beisi Zhou <[email protected]>
1 parent 545ef08 commit 26c148f

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,24 +106,16 @@ Created : 2/8/2016 11:21:45 PM
106106
Updated : 2/8/2016 11:21:45 PM
107107
```
108108

109+
This command gets the certificate named `TestCert01` from the key vault named `ContosoKV01`
110+
109111
### Example 2: Get cert and save it as pfx
110112
```powershell
111-
$cert = Get-AzKeyVaultCertificate -VaultName $vaultName -Name $certName
112-
$secret = Get-AzKeyVaultSecret -VaultName $vaultName -Name $cert.Name -AsPlainText
113-
# Write to a file
114-
Set-Content -Path cert.pfx -Value $secret -PassThru
115-
```
116-
117-
```output
118-
-----BEGIN PRIVATE KEY-----
119-
******************************
120-
-----END PRIVATE KEY-----
121-
-----BEGIN CERTIFICATE-----
122-
******************************
123-
-----END CERTIFICATE-----
113+
$CertBase64 = Get-AzKeyVaultSecret -VaultName $vaultName -Name $certName -AsPlainText
114+
$CertBytes = [Convert]::FromBase64String($CertBase64)
115+
Set-Content -Path cert.pfx -Value $CertBytes -AsByteStream
124116
```
125117

126-
This command gets the certificate named `$certName` from the key vault named `$vaultName`. These commands access secret `$cert.Name` and then save the content as a pfx file.
118+
This command gets the certificate named `$certName` from the key vault named `$vaultName`. These commands access secret `$certName` and then save the content as a pfx file.
127119

128120
### Example 3: Get all the certificates that have been deleted but not purged for this key vault.
129121
```powershell

0 commit comments

Comments
 (0)