Getting Started with Azure Functions in PowerShell

Azure Functions is an event driven, compute-on-demand experience that extends the existing Azure application platform with capabilities to implement code triggered by events occurring in virtually any Azure or 3rd party service as well as on-premises systems. Azure Functions allows developers to take action by connecting to data sources or messaging solutions, thus making it easy to process and react to events. Azure Functions scale based on demand and you pay only for the resources you consume.

You can create functions in the Azure portal, but manual intervention isn’t good for scaling continuous delivery.

Create an Azure Function App

This link walks you through creating an Azure Function App. Be sure to grab the Resource Group Name and the SiteName so you can plug it into the PowerShell script.

Automate it with PowerShell

Using the New-AzureRmResource Azure cmdlet, you’ll setup the required parameters. $props is a PowerShell hashtable that holds the config information for the function. Here you’ll create a timerTrigger and put it on a schedule. In the files hashtable, the key value pair are the name of the PowerShell file to be created and the value is valid PowerShell.

In this example. I’ll leverage the .NET framework, creating a Net.WebClient, so I can download finance data from the Yahoo Finance web service.

This is a quick tour. You can also upload JavaScript code to run as a function. Plus, you could read the PowerShell from a file rather then hard coding it in a script.

Lastly

This is just scratching the surface. For example, you can create functions in many different languages and there other Trigger types as well. Plus, we only outputted information to the log, there’s much more to explore.

Leave a Reply

Your email address will not be published. Required fields are marked *