I am trying to access key vault secret from Timer Triggered Powershell Azure function app using the below steps.
- Created TimerTrigger Powershell Function app.
- Registered function app with AD app in Express Mode.
- Enabled Managed Service Identity in function App.
- Created KeyVault in the same resource group and added function app under keyvault accesspolicies .
- Created a new secret under keyvault secrets.
Used below code to access keyvault in function app.
$NewTestSecret = Get-AzureKeyVaultSecret -VaultName FunctionAppTestKeyVault -Name TestSecret $NewTestSecretVaule = $NewTestSecret.SecretValueText Write-Output $NewTestSecretVaule
Getting the below errors.Not sure what additional steps I am missing. Any responses are really appreciated.
CategoryInfo : InvalidOperation: (:)
[Get-AzureKeyVaultSecret], PSInvalidOperationException
FullyQualifiedErrorId : InvalidOperation,Microsoft.Azure.Commands.KeyVault.GetAzureKeyVaultSecret 2018-04-14T17:45:00.709 [Error] Exception while executing function: Functions.TimerTriggerTestPowershell1. Microsoft.Azure.WebJobs.Script: PowerShell script error. Microsoft.Azure.Commands.ResourceManager.Common: Run Login-AzureRmAccount to login.
Login-AzureRmAccount
. Have you done that? – Shawn Tabrizi