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.
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