Visual Studio Azure Functions App Project for PowerShell

Share on facebook
Share on twitter
Share on linkedin

Serverless computing has become increasingly popular by allowing developers to deploy services without any concerns about the underlying infrastructure.  Serverless provides the capability to run your services as fast as possible where one of the most interesting aspects is that the cost is based on how many times the service is accessed.  In many circumstances this provides a cost effective solution by not having pay for a minimum amount of infrastructure the entire time.  This consumption based model encourages services to be execute quickly resulting in a microservice oriented design.

In Azure, you can leverage severless computing using Azure Functions.  Azure Functions provide a platform for deploying small bits of code.  These functions can be created using C# script, F#, Bash, Batch, JavaScript, Php, Python, TypeScript, and PowerShell.  

I had a PowerShell script to run an infrastructure scan against Azure.  I needed it to run from outside the network.  I initial looked into Container Instances but the solution continued to grow in complexity.  Since Azure Functions can run PowerShell scripts, I felt like this was much better fit.

Using the Azure Portal, I created a HttpTrigger – PowerShell function.  I pasted in the PowerShell script and modified the template parameters to pass in the values my script was expecting.  I had a running PowerShell function.


Once, I got it working, I pulled down the ARM template to use for my infrastructure code.  Next, I wanted to manage and deploy my Azure Function using an Azure Function App project in Visual Studio 2017.  I downloaded the Visual Studio 2017 Tools for Azure Functions.  I used Visual Studio and the Azure Functions project template to create the function app.  When I created the project, I realized that the Visual Studio Azure Function App project only supports creating C# script functions.  This left me unsure how I was going to deploy my function.  While there might be other ways to accomplish this, I found a simple process starting with the Azure Portal.  In the portal, there is a Download app content button that allows you to download the app.


If you select this button, it will prompt you with the option to download the content and Visual Studio project.  Once you do this, you can unzip it to a folder and open the project in Visual Studio.


At this point I had the source code for my PowerShell Azure Function in my Visual Studio project where I  published this to a repo in my VSTS account.

To incorporate your Azure Function into a continuous delivery process, take a look at this article.  Azure Functions – Prepare for continuous delivery

More to explore