---
title: "How to Execute PowerShell Azure Functions with HTTP Triggers"
description: "Learn how to execute and test Azure Functions in PowerShell via HTTP using both the Azure Portal and PowerShell’s Invoke-RestMethod cmdlet."
canonical: "https://adamtheautomator.com/azure-functions-powershell-2/"
---

# How to Execute PowerShell Azure Functions with HTTP Triggers

> Learn how to execute and test Azure Functions in PowerShell via HTTP using both the Azure Portal and PowerShell’s Invoke-RestMethod cmdlet.

Source: https://adamtheautomator.com/azure-functions-powershell-2/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Execute PowerShell Azure Functions with HTTP Triggers](https://adamtheautomator.com/wp-content/uploads/2022/09/How-to-Execute-PowerShell-Azure-Functions-with-HTTP-Triggers.jpg)

# How to Execute PowerShell Azure Functions with HTTP Triggers

[![](https://secure.gravatar.com/avatar/d0b9d42e21e5622713f8b693aa5c0f9244d5f7dd200ed29b8398f52dee5de337?s=192&d=mm&r=g)Adam Bertram](https://adamtheautomator.com/author/adam-bertram/)5 October 20224 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Azure Functions](/tag/azure-functions/)[Powershell Administration](/tag/powershell-administration/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Executing the Azure Functions PowerShell HTTP Trigger via the Azure Portal](#executing-the-azure-functions-powershell-http-trigger-via-the-azure-portal)
*   [Executing the Azure Functions PowerShell HTTP Trigger via PowerShell](#executing-the-azure-functions-powershell-http-trigger-via-powershell)
*   [Summary](#summary)

So you’ve created a handy Azure function app with a function inside running your favorite PowerShell script. Now what? If you’ve created that function with an HTTP trigger [as shown in the last tutorial in this series](https://adamtheautomator.com/azure-functions-powershell-1/), it’s time to execute that script and see what happens!

By the end of this tutorial, you’ll know how to execute an Azure function written in PowerShell.

## Prerequisites

*   A pre-built Azure Function app with PowerShell function using an HTTP trigger
*   Visual Studio (VS) Code setup with required extensions
*   PowerShell v7+

> _This tutorial is #2 in the series we’re calling Building PowerShell Azure Functions. This tutorial assumes you already have an Azure function running PowerShell created with an HTTP trigger as demoed in the last tutorial._

## Executing the Azure Functions PowerShell HTTP Trigger via the Azure Portal

There are a few different ways to execute an Azure function that uses an HTTP trigger. You can use the Azure Portal or pick any method you’d typically call an HTTP method like Postman or [PowerShell itself](https://adamtheautomator.com/invoke-restmethod/)! The beauty of an HTTP trigger for a PowerShell script is the ubiquitous ways to run it.

Assuming you have a function already built:

1\. Head over to the [Azure Portal](https://portal.azure.com/) and open the function app. You’ll see a Functions link, as shown below.

![The Functions menu item](https://adamtheautomator.com/wp-content/uploads/2022/09/image-776.png)

The Functions menu item

2\. Click Functions. You should see a function called _ExecutePowerShellScriptonHTTPEvent_ if you followed the [previous tutorial in this series](https://adamtheautomator.com/azure-functions-powershell-1/).

> _If you’re bringing your own Azure function, as long as it’s a PowerShell function triggered via HTTP, the following steps will still work._

3\. Click on the function and click on the Code + Test item.

![The Azure Portal testing screen menu item](https://adamtheautomator.com/wp-content/uploads/2022/09/image-777.png)

The Azure Portal testing screen menu item

On the Code + Test screen, you’ll see the _run.ps1_ script that’s part of the function.

![The main executing PowerShell script, run.ps1](https://adamtheautomator.com/wp-content/uploads/2022/09/image-778.png)

The main executing PowerShell script, run.ps1

> _An Azure function built for PowerShell consists of a few different files such as run.ps1, the main executing script, requirements.psd1 for defining PowerShell module prerequisites, and profile.ps1 to execute PowerShell when the function app starts up._

The code in _run.ps1_ in the example above is the HTTP trigger template code provided by Microsoft. This code doesn’t do much for now but will provide some output to understand the execution.

4\. Click on the Test/Run button where a handy HTTP blade pops up, allowing you to specify the method, query, and body you’d like to pass to the function.

![Executing an Azure Functions PowerShell script](https://adamtheautomator.com/wp-content/uploads/2022/09/image-779.png)

Executing an Azure Functions PowerShell script

By default, HTTP-triggered functions allow for HTTP GET and POST methods. You can add or remove allowed HTTP methods by changing the function.json file inside of the function along with other parameters outside the scope of this tutorial.

![The function.json file](https://adamtheautomator.com/wp-content/uploads/2022/09/image-780.png)

The function.json file

> _When you create an Azure function via VS Code, the function will be read-only inside of the Azure Portal. To make any changes, you must modify any files locally on your PC and deploy the changes to Azure._

5\. For now, simply click on Run without providing any other information to see what happens. You should see the function run successfully, indicated by an HTTP 200/OK response code.

![HTTP output for the Azure function](https://adamtheautomator.com/wp-content/uploads/2022/09/image-781.png)

HTTP output for the Azure function

The text you see is generated via an [output binding](https://learn.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings?tabs=csharp) returned as the HTTP body using the Push-OutputBinding cmdlet inside the _run.ps1_ script, as shown below.

![Output bindings with Push-OutputBinding](https://adamtheautomator.com/wp-content/uploads/2022/09/image-782.png)

Output bindings with Push-OutputBinding

Notice there’s a Write-Host reference in the _run.ps1_ script above. Console output is returned via the log stream and is where you can see all internal logging information and any output the _run.ps1_ script sent.

![Monitoring Azure Function logs](https://adamtheautomator.com/wp-content/uploads/2022/09/image-783.png)

Monitoring Azure Function logs

6\. Now, click on Test/Run again, and this time change the HTTP method to GET and add a Query name of name. If you’re using this series’ original function, the _run.ps1_ script has code that handles the name query parameter, as shown below.

![Reading HTTP body input and changing binding output](https://adamtheautomator.com/wp-content/uploads/2022/09/image-784.png)

Reading HTTP body input and changing binding output

You’ll now see that the function returns HTTP/200, but the body was changed based on the query value.

![New output binding value](https://adamtheautomator.com/wp-content/uploads/2022/09/image-785.png)

New output binding value

## Executing the Azure Functions PowerShell HTTP Trigger via PowerShell

Since HTTP triggers attached to Azure functions provide a standardized HTTP interface, you can execute and test your Azure PowerShell functions with any method capable of sending HTTP requests, including PowerShell!

PowerShell has two different cmdlets that make HTTP requests; [Invoke-WebRequest](https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwiTuuX0lbP6AhW9FVkFHRQvD3YQFnoECAkQAQ&url=https%3A%2F%2Fadamtheautomator.com%2Finvoke-webrequest%2F&usg=AOvVaw3X5bk27IRwcRZ1BoNOdd5p) and [Invoke-RestMethod](https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwjaufb9lbP6AhV8FFkFHXPWDgwQFnoECAkQAQ&url=https%3A%2F%2Fadamtheautomator.com%2Finvoke-restmethod%2F&usg=AOvVaw0lL2fydNCZfyLBoxKS0rYb). Since our Azure function is essentially a little API at this point returning JSON, the Invoke-RestMethod will be the best bet for testing.

1\. To execute the Azure function with PowerShell, you must get the endpoint to query. To do that, open the function, click on Code + Test, and then on Get function URL.

You’ll see an option for selecting a Key. This key comes from the authentication level when you create the Function App. Authentication is out of scope for this tutorial, but if you’d like to dig deeper into this topic, check out [Azure Functions HTTP – Authorization Levels](https://vincentlauzon.com/2017/12/04/azure-functions-http-authorization-levels/).

![Getting the Azure Functions PowerShell endpoint](https://adamtheautomator.com/wp-content/uploads/2022/09/image-786.png)

Getting the Azure Functions PowerShell endpoint

You can find all of the API

![Azure Function App keys](https://adamtheautomator.com/wp-content/uploads/2022/09/image-787.png)

Azure Function App keys

2\. Keep the **Key** to default and copy the **URL**. This action will copy the endpoint to query along with the API key to authenticate to the function.

3\. Open PowerShell on your local computer, run the Invoke-RestMethod cmdlet, and pass the URL you just copied. The tutorial’s demo function URL is provided below.

```powershell
Invoke-RestMethod -Uri 'https://powershellfunctionsdemo.azurewebsites.net/api/ExecutePowerShellScriptonHTTPEvent?code=<My API Key here>'
```

You’ll see the same output the Azure Portal returned.

![Testing the Azure Functions PowerShell function with no query parameters](https://adamtheautomator.com/wp-content/uploads/2022/09/image-788.png)

Testing the Azure Functions PowerShell function with no query parameters

4\. Now, pass in an HTTP query by including the key/value pair inside of the URL, making the URL now https://powershellfunctionsdemo.azurewebsites.net/api/ExecutePowerShellScriptonHTTPEvent?name=myname&code=\\

Again, you’ll see the same output as before in the Azure Portal but now in your PowerShell console.

![Testing the Azure Functions PowerShell function with a query parameter](https://adamtheautomator.com/wp-content/uploads/2022/09/image-789.png)

Testing the Azure Functions PowerShell function with a query parameter

Giving your Azure PowerShell functions an HTTP trigger allows you to execute the script from many different sources, including code and other tools.

## Summary

This tutorial taught you how to execute a simple PowerShell Azure function. If you’ve followed both tutorials in this series, you should now be able to create and execute PowerShell Azure Functions and take your PowerShell scripts to the cloud!

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fazure-functions-powershell-2%2F&text=How%20to%20Execute%20PowerShell%20Azure%20Functions%20with%20HTTP%20Triggers)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fazure-functions-powershell-2%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fazure-functions-powershell-2%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/09/Building-PowerShell-Azure-Functions-with-VS-Code-Series.png)

### [Building PowerShell Azure Functions with VS Code \[Series\]](/azure-functions-powershell-1/)

Running PowerShell in Azure Functions gives your scripts infinite resources and flexibility. Learn how to cloudify your PowerShell scripts with Azure Functions!

![](https://adamtheautomator.com/wp-content/uploads/2022/02/Autonomous-Persona-Management-using-1E-Tachyons-PowerShell-Toolkit.jpg)

### [Autonomous Persona Management using 1E Tachyon’s PowerShell Toolkit](/1e-powershell-3/)

Learn how to manage thousands of endpoints with dynamic tagging capabilities with 1E’s Tachon.

![](https://adamtheautomator.com/wp-content/uploads/2022/02/Getting-Started-with-1Es-Tachyon-and-PowerShell-1.jpg)

### [Getting Started with 1E’s Tachyon and PowerShell](/1e-powershell/)

Wrangle your endpoints with 1E’s Tachyon product and PowerShell in this in-depth tutorial!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
