Skip to content

Commit 41f9a84

Browse files
authored
Merge pull request Azure#10018 from juntakata/patch-1
Add how to get cert and save it as pfx
2 parents d361892 + 359a3bb commit 41f9a84

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,33 @@ Certificate : [Subject]
9494
[Thumbprint]
9595
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
9696
97+
KeyId : https://contoso.vault.azure.net:443/keys/TestCert01/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
98+
SecretId : https://contoso.vault.azure.net:443/secrets/TestCert01/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
9799
Thumbprint : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
98100
Tags :
99101
Enabled : True
100102
Created : 2/8/2016 11:21:45 PM
101103
Updated : 2/8/2016 11:21:45 PM
102104
```
103105

104-
This command gets the certificate named TestCert01 from the key vault named ContosoKV01.
106+
### Example 2: Get cert and save it as pfx
107+
This command gets the certificate named TestCert01 from the key vault named ContosoKV01. To download the certificate as pfx file, run following command. These commands access SecretId and then save the content as a pfx file.
105108

106-
### Example 2: Get all the certificates that have been deleted but not purged for this key vault.
109+
```powershell
110+
$cert = Get-AzKeyVaultCertificate -VaultName "ContosoKV01" -Name "TestCert01"
111+
$secret = Get-AzKeyVaultSecret -VaultName $vaultName -Name $cert.SecretId
112+
113+
$secretByte = [Convert]::FromBase64String($secret.SecretValueText)
114+
$x509Cert = new-object System.Security.Cryptography.X509Certificates.X509Certificate2
115+
$x509Cert.Import($secretByte, "", "Exportable,PersistKeySet")
116+
$type = [System.Security.Cryptography.X509Certificates.X509ContentType]::Pfx
117+
$pfxFileByte = $x509Cert.Export($type, $password)
118+
119+
# Write to a file
120+
[System.IO.File]::WriteAllBytes("KeyValt.pfx", $pfxFileByte)
121+
```
122+
123+
### Example 3: Get all the certificates that have been deleted but not purged for this key vault.
107124
```powershell
108125
PS C:\> Get-AzKeyVaultCertificate -VaultName 'contoso' -InRemovedState
109126
@@ -135,7 +152,7 @@ Id : https://contoso.vault.azure.net:443/certificates/test2
135152

136153
This command gets all the certificates that have been previously deleted, but not purged, in the key vault named Contoso.
137154

138-
### Example 3: Gets the certificate MyCert that has been deleted but not purged for this key vault.
155+
### Example 4: Gets the certificate MyCert that has been deleted but not purged for this key vault.
139156
```powershell
140157
PS C:\> Get-AzKeyVaultCertificate -VaultName 'contoso' -Name 'test1' -InRemovedState
141158
@@ -178,7 +195,7 @@ Id : https://contoso.vault.azure.net:443/certificates/test1/7fe4
178195
This command gets the certificate named 'MyCert' that has been previously deleted, but not purged, in the key vault named Contoso.
179196
This command will return metadata such as the deletion date, and the scheduled purging date of this deleted certificate.
180197

181-
### Example 4: List certificates using filtering
198+
### Example 5: List certificates using filtering
182199
```powershell
183200
PS C:\> Get-AzKeyVaultCertificate -VaultName "ContosoKV01" -Name "test*"
184201

0 commit comments

Comments
 (0)