RazorSPoint
RazorSPoint

Accessing App Setting from Azure Functions with PowerShell

Sebastian SchützeSebastian Schütze

I am currently trying out a lot with Azure Functions. With CI / CD pipelines and how to automatically deploy them. But also trying out C# and PowerShell to be used with Azure Functions. When I came to use PowerShell with Azure Functions, I got to a problem.

I am using an Azure Function with a queue trigger to read from that trigger. This function currently is including an administrator account and a password in clear text. Not good I though. I could encrypt it before putting it into the queue and then decrypt it when getting it out. But I wanted to have these settings rather saved in the app settings of the function. But how to access these app settings?

Lets see the following PowerShell Script that you could use

$result = ls env: | out-string

write-output $result

What this does is basically getting all the environment variables, converting them into a string and output them to the logs. What you get is the following

There you can see variables starting with the name APPSETTING_ this means you could just access any app settings with the environment prefix. For example we want to access the standard variable QueueConnectionString. This would look like this

$result = ls env:APPSETTING_QueueConnectionString
$result.value

So now you know how to access app settings this PowerShell 🙂

 

Sebastian is an Azure Nerd with focus on DevOps and Azure DevOps (formerly VSTS) that converted from the big world of SharePoint and O365. He was working with O365 since 2013 and loved it ever since. As his focus shifted in 2017 to more DevOps related topics in the Microsoft Stack. He learned to love the possibilities of automation. Besides writing articles in his blog and German magazines, he is still contributing to the SharePoint Developer Community (and PnP SharePoint) to help to make the ALM part a smoother place to live in.