Sync-AzKeyVaultWithUserSecrets
is a PowerShell command that copies all secrets from an Azure Key Vault into the local dotnet user‑secrets
store of the nearest .NET project.
- PowerShell 5.1 or newer (Windows) or PowerShell 7+ (cross‑platform).
- .NET SDK 5.0 or newer installed (
dotnet
CLI). - Azure PowerShell modules Az.Accounts ≥ 2.12.0 and Az.KeyVault ≥ 4.10.0.
- Permissions to read secrets in the specified Key Vault.
Install-Module SyncAzKeyVaultWithUserSecrets
(or follow the instructions at https://www.powershellgallery.com/packages/SyncAzKeyVaultWithUserSecrets)
-
Copy
SyncAzKeyVaultWithUserSecrets.psm1
andSyncAzKeyVaultWithUserSecrets.psd1
into a folder namedSyncAzKeyVaultWithUserSecrets
that sits in any path listed in$env:PSModulePath
. Example:$moduleRoot = "$HOME\Documents\PowerShell\Modules\SyncAzKeyVaultWithUserSecrets" New-Item -ItemType Directory -Path $moduleRoot -Force Copy-Item .\*.psm1,*.psd1 -Destination $moduleRoot
-
Import the module:
Import-Module SyncAzKeyVaultWithUserSecrets
Sync-AzKeyVaultWithUserSecrets -KeyVaultName "<vault-name>"
Parameter | Type | Mandatory | Description |
---|---|---|---|
-KeyVaultName |
String | Yes | Name of the Azure Key Vault whose secrets you want to use locally in your .NET project. |
Sync-AzKeyVaultWithUserSecrets -KeyVaultName "my-kv-dev"
Walks up to the first .csproj, prompts you to map each secret, stores them with dotnet user‑secrets
.
Set-Location src\Api
Sync-AzKeyVaultWithUserSecrets -KeyVaultName "my-kv-test"
Issues, ideas and pull requests are welcome!
- Fork the repository: https://github.com/axelkjonsberg/SyncAzKeyVaultToUserSecrets
- Create a feature branch (
git checkout -b feature/some-concisely-named-improvement
) - Commit your changes and open a PR.