Skip to content

Commit 60d7578

Browse files
authored
Merge pull request #200411 from jlichwa/main
Add powershell commands
2 parents 638726a + a024c2b commit 60d7578

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

articles/key-vault/keys/how-to-configure-key-rotation.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ Key rotation policy settings:
5353
- Rotation time: key rotation interval, the minimum value is seven days from creation and seven days from expiration time
5454
- Notification time: key near expiry event interval for Event Grid notification. It requires 'Expiry Time' set on rotation policy and 'Expiration Date' set on the key.
5555

56-
:::image type="content" source="../media/keys/key-rotation/key-rotation-1.png" alt-text="Rotation policy configuration":::
57-
5856
> [!IMPORTANT]
5957
> Key rotation generates a new key version of an existing key with new key material. Ensure that your data encryption solution uses versioned key uri to point to the same key material for encrypt/decrypt, wrap/unwrap operations to avoid disruption to your services. All Azure services are currently following that pattern for data encryption.
6058
59+
:::image type="content" source="../media/keys/key-rotation/key-rotation-1.png" alt-text="Rotation policy configuration":::
60+
6161
## Configure key rotation policy
6262

6363
Configure key rotation policy during key creation.
@@ -105,6 +105,19 @@ Set rotation policy on a key passing previously saved file using Azure CLI [az k
105105
az keyvault key rotation-policy update --vault-name <vault-name> --name <key-name> --value </path/to/policy.json>
106106
```
107107

108+
### Azure PowerShell
109+
110+
Set rotation policy using Azure Powershell [Set-AzKeyVaultKeyRotationPolicy](/powershell/module/az.keyvault/set-azkeyvaultkeyrotationpolicy) cmdlet.
111+
112+
```powershell
113+
Get-AzKeyVaultKey -VaultName <vault-name> -Name <key-name>
114+
$action = [Microsoft.Azure.Commands.KeyVault.Models.PSKeyRotationLifetimeAction]::new()
115+
$action.Action = "Rotate"
116+
$action.TimeAfterCreate = New-TimeSpan -Days 540
117+
$expiresIn = New-TimeSpan -Days 720
118+
Set-AzKeyVaultKeyRotationPolicy -InputObject $key -KeyRotationLifetimeAction $action -ExpiresIn $expiresIn
119+
```
120+
108121
## Rotation on demand
109122

110123
Key rotation can be invoked manually.
@@ -122,6 +135,14 @@ Use Azure CLI [az keyvault key rotate](/cli/azure/keyvault/key#az-keyvault-key-r
122135
az keyvault key rotate --vault-name <vault-name> --name <key-name>
123136
```
124137

138+
### Azure PowerShell
139+
140+
Use Azure PowerShell [Invoke-AzKeyVaultKeyRotation](/powershell/module/az.keyvault/invoke-azkeyvaultkeyrotation) cmdlet.
141+
142+
```powershell
143+
Invoke-AzKeyVaultKeyRotation -VaultName <vault-name> -Name <key-name>
144+
```
145+
125146
## Configure key near expiry notification
126147

127148
Configuration of expiry notification for Event Grid key near expiry event. You can configure notification with days, months and years before expiry to trigger near expiry event.

0 commit comments

Comments
 (0)