In this Azure tutorial, we will discuss how to create a PowerShell Azure Function.
Subscribe to Our YouTube Channel for more videos.
Well Before going to the actual development, you can check out What Is Azure Functions.
Table of Contents
Create PowerShell Azure Function Visual Studio Code
Before starting, we should know the Prerequisites for developing the PowerShell Azure Function.
Prerequisites
- Make sure to install the Visual Studio Code along with Azure Functions Extensions if you have not yet installed the Visual Studio Code. Install the Visual Studio Code now.
- An Azure Free Account or Azure Subscription.
Azure Functions PowerShell Examples
Now that we have all the Prerequisites needed for the development activity Let’s start the actual development.
- The first step is to open Visual Studio Code from your local machine and then click on the Azure Button from the left side. Next, click on the Create New Project button in the Functions Explorer, as shown below.

2. The next step is to choose the location to save your PowerShell Azure Function project. You can click the Browse button to navigate to the local path on your development machine where you want to save it.

3. Now, select PowerShell from the window below. It is very important to choose PowerShell.

4. The next step is to select the trigger as the template. Based on your requirements, you can choose an HTTP trigger that will invoke your Azure Function or another type of trigger.

5. In the next step, Provide a unique name for your Azure Function and hit Enter.

6. Now the time to choose the Authorization Level as highlighted below

7. You can click on the Open in new window option to open the project in a separate window, as shown below

8. Now, it will start creating the PowerShell Azure Function. Once it creates the project, you can see the code below is for the run.ps1 file.
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."
# Interact with query parameters or the body of the request.
$name = $Request.Query.Name
if (-not $name) {
$name = $Request.Body.Name
}
$body = "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
if ($name) {
$body = "Hello, $name. This HTTP triggered function executed successfully."
}
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $body
})
Run PowerShell Azure Function Locally
Now, Our Azure Function Project is successfully created. The next step is to Test the PowerShell Azure Function Locally. Click on the Run button from the left side, or press the F5 button to run the PowerShell Azure Function Project in Visual Studio Code IDE.
You can see the PowerShell Azure Function Project ran successfully without any issues and provided us with the URL below
MyNewPowerShellAzureFN: [GET,POST] http://localhost:7071/api/MyNewPowerShellAzureFN

Now Open your Favorite browser and paste the URL. You can see below that it is prompting us to append the name value as a query string parameter along with the function URL

After appending the name value as the query string parameter, you can see we got the expected output below

We have created the PowerShell Azure Function in Visual Studio Code and verified that it is working correctly. Now, it is time to deploy it to Azure.
Deploy PowerShell Azure Function From Visual Studio Code
Like other Azure Functions, we can also deploy PowerShell Azure Functions from Visual Studio Code with a few easy steps. Follow the steps below to publish PowerShell Azure Functions from Visual Studio Code.
The first step is to click on the Azure button again and then click on the Deploy to Function App button, as highlighted below.

The next step is to click the + Create new Function App in Azure button.

Now, in the window below, provide a unique name for the function app and hit Enter.

Select the runtime stack version from the window below. Select PowerShell Core 7.0 as the runtime stack. Note that you should not select the PowerShell Core 6.2 version here, as it has already been deprecated.

The next step is to select the location for the new Azure resource. Now, it will start creating all the Azure components needed for the deployment, which will take a few seconds. It will then show you how to deploy the PowerShell Azure Function to the Azure Portal.

If you see the output window, it will start creating the Azure components individually. Then, after a few minutes, it will successfully deploy your PowerShell Azure Function To Azure.

This is how to create and deploy a PowerShell Azure Function using VS Code.
How To Create A PowerShell Azure Function Using The Azure Portal
Follow the steps below.
- Log in to the Azure Portal (https://portal.azure.com/)
- Search for the Function App in the Azure Portal and click on the search result

3. On the Azure Function App page, Click the + Add button to create a new Azure Function App.
Then, Provide the below Details on the Create Function App Page
- Subscription: You must Choose the Correct Azure Subscription to create the PowerShell Azure Function.
- Resource Group: You can choose your existing Resource Group, or if you don’t have one, click on Create New Link to create a new One.
- Function App name: Provide a unique name for your Azure Function App.
- Publish: You need to Choose the Code option here.
- Runtime Stack: Choose the PowerShell Core as the Runtime Stack.
- Version: Choose the latest version of PowerShell Core here.
- Region: Select the Region for your Azure Resource.
Keep the other tab details as they are. After you provide all the above details, click the Review + Create button.

Another thing to note is that Azure Function using the PowerShell Core is now only supported for the Windows operating system. If you navigate to the Hosting tab, you can see that the Linux option is disabled.

4. After you click on the Review + Create button, the details you provided will be validated. If all the option values you provided are correct, the Create button will be enabled, which you can see in the next window. Now click on the Create button to create the Azure Function App.
5. Creating the Azure Function App will take a few seconds. As you can see below, the deployment is completed. Click the Go to Resource button to navigate to the Azure Function App you created.

Creating PowerShell Azure Function
The next step is to create the Azure Function since our PowerShell Azure Function App is ready now. Click on the Functions option from the left navigation and then click on the + Add button on the Function App page, as highlighted below.

Next, on the Add Function page, Select the Development environment as Develop in the portal, Select the HTTP trigger as the Azure Function template, Provide a name for the Azure Function, select the Authorization Level as Function, and finally, click on the Add button to create the PowerShell Azure Function, as shown below.

The PowerShell Azure Function has been successfully created. As highlighted below, click on the Code + Test option from the left navigation to see the code for the Run.ps1 file.

Below is the complete code for the run.PS1 file. You can modify the code based on your requirements if you want to modify it in the run.PS1 file and then click on the Save button to save the modified code.
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."
# Interact with query parameters or the body of the request.
$name = $Request.Query.Name
if (-not $name) {
$name = $Request.Body.Name
}
$body = "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
if ($name) {
$body = "Hello, $name. This HTTP triggered function executed successfully."
}
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $body
})
Now, to test the Azure Function, click on the Test/Run button, select the HTTP method, Provide the Body in JSON format in the Input Window, and then click on the Run button.

As you will see below in the Output window, we got the HTTP response code 200 OK and the proper HTTP response content.

FAQs
What are the Benefits of Azure Functions using PowerShell
We will get a couple of benefits by creating Azure functions using PowerShell. Those are as follows.
- You will get excellent support for the hybrid environments.
- Integrating with Azure Portal and Visual Studio Code IDE is pretty straightforward.
You may also like Following the below Articles
- How To Access Azure Functions wwwroot Folder
- How To Create Node.js Azure Functions
- Calling An Azure Function From Power Automate (MS Flow)
Wrapping Up
This article discussed how to create PowerShell Azure Functions and Azure Functions PowerShell Examples. I hope you have enjoyed this article!!!

I am Rajkishore, and I am a Microsoft Certified IT Consultant. I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machines, Logic Apps, PowerShell Commands, CLI Commands, Machine Learning, AI, Azure Cognitive Services, DevOps, etc. Not only that, I do have good real-time experience in designing and developing cloud-native data integrations on Azure or AWS, etc. I hope you will learn from these practical Azure tutorials. Read more.
