I am writing an Azure function app in powershell (runtime 2.0.12507.0).
To perform an operation in my function app, it must authenticate with Azure using the Connect-AzAccount function. I store the sensitive credentials used to connect in 'Manage > Function keys', but I cannot access these keys programmatically.
I have already tried using $Env:NAME_OF_MY_KEY to access the key value, but the value is coming up as null or empty when I try this. From what I understand, 'Function keys' are simply environment variables, and should be accessible this way.
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
# Get the service principal secret as a secure string
$secpasswd = ConvertTo-SecureString $env:SP_Secret -AsPlainText -Force
# Create a new PSCredential using the principal secret and app id
$mycreds = New-Object System.Management.Automation.PSCredential ($env:SP_AppID, $secpasswd)
# Connect to the Azure account using the powershell credentials and tenant id
$result = Connect-AzAccount -ServicePrincipal -Tenant $env:SP_Tenant -Credential $mycreds
I am expecting to be able to access these function keys; however, even if I echo out the value of $env:SP_Secret, I still get an empty string. Is this the correct way to access function keys in an Azure Function App?


