In this Azure tutorial, we will discuss Create Azure Function using Visual Studio Code and PowerShell.
Subscribe to Our YouTube Channel for more videos
Table of Contents
Create Azure Function using Visual Studio Code and PowerShell
Well, here we will discuss Create Azure Function using Visual Studio Code. Before that, We should know the Prerequisites needed or the things needed to Set Up Your Environment to start with the development activity.
Set Up Your Environment to Create function app in Visual Studio Code
Prerequisites
Below are the things needed before you start to Build Your First Azure Function in Visual Studio Code.
- The first thing we need is an Azure Account or Azure Subscription. If you don’t have an Azure Account till now, create an Azure Free Account now.
- Visual Studio Code needs to be installed. If you don’t have Visual Studio Code installed on your machine, then install Visual Studio Code now.
- The Azure Function Extensions for the Visual Studio Code.
How To Create Azure Functions In Visual Studio Code
Now that we have everything needed for the development activities Let’s start the actual development. Follow the below steps to Create Azure Functions using Visual Studio Code.
1. Open the Visual Studio Code in our local System and click on the Extensions button from the left side. Now search for the Azure Functions and then click on the Install button below to install the Azure Functions extension in the Visual Studio Code.

2. Now you can see that Azure Functions extensions have been installed successfully.

3. Now click on the Azure button from the left side and then click on the Create New Project icon from the top, as shown below.

4. Now, click the Browse button on the Create a new project window to select a Project location.

5. Now, select a language to build the Azure Function; I am choosing the language option here as C#. The available language options are Javascript, TypeScript, C#, Python, Java, and PowerShell.

Build an HTTP Trigger Azure Function
6. Now, you need to select a trigger for your Azure Function. I will choose the option of HTTP Trigger.

7. Provide the Function name and click on the Enter button. Now it will ask for the NameSpace name, and then click the Enter button in the next window.

8. Select the AccessRights option as Anonymous on the Create new HTTP Trigger window.

9. You can see below that the Azure function was created successfully.

How to run Azure function locally in Visual Studio Code
10. Now click on the Run button from the left side or press F5 to run the project.

Oh, I got the error “Configured debug type ‘coreclr’ is not supported” like below.

So to fix the error “Configured debug type ‘coreclr’ is not supported” ” click on the Extensions button from the left side, search for “C# Extensions,” and click on the install button to install the C# extensions in Visual Studio Code.

Now You can see the C# extension has been successfully installed. You can set the Color Theme by clicking the Set Color Theme.

Okay, Now Run the Project again. I got the warning “You must have the Azure Functions Core Tools installed to debug your local functions” again this time. Just click on the Install button.

Once you install this, this time the project will run successfully without any issues. You can see below that the project ran successfully.

How to locally test Azure functions
For testing Azure functions locally, You can copy the function URL and paste it into the Browser. http://localhost:7071/api/MyNewDemoAzureFunction.
Once you put the URL in the Browser, you can see the default message “This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.”

Okay, now let’s provide a value for the name parameter in the query string. Now you can see we got the expected outcome as below.
Hello, Raj. This HTTP-triggered function was executed successfully.

Now, let’s test this function on the Postman app. Open the Postman on your local machine, copy and paste this URL, choose the GET option, and click the Send button. We got the expected output with the response code 200 OK.

This is the way to Build Azure function in Visual Studio code. Now it’s time to Deploy the Azure function from Visual Studio code.
You can also check out How to Debug Azure Function locally in Visual Studio Code
Deploy Azure function from Visual Studio code
Now, we have developed our Azure Function in Visual Studio Code. So the next step is we need to deploy the Azure function from the Visual Studio code. Follow the below steps for the deployment.
Click on the Azure button from the left side and then click on the Deploy to Function App… icon as highlighted below.

It might ask you to enter your Azure Credentials. Provide the credentials, and then once signed in, click on the + Create new Function App in Azure

Now, provide a unique name for the Function App and then click on Enter.

Now, provide a location for the resource

You can see below that the deployment was completed successfully without any issues.

Now, to make sure that the Azure function is deployed successfully in the Azure Portal, Log in to the Azure Portal and navigate to the App services. You can see the Azure Function app that we have deployed from the Visual Studio Code.

Now click on that and then on the App service window. Click on the Functions link from the left side navigation.

You can able to see the function that we have created from the Visual Studio Code.

The next step is to check in the Postman app to see if the function is working fine. To do that, click on the function and the Get Function URL from the top.

On the Get Function URL window, click on the Copy button to copy the Function URL.

The URL will look like below
https://mynewfunctionapp235.azurewebsites.net/api/MyNewDemoAzureFunction?
Now, to test this, Open the Postman app, Paste the above URL, choose the GET operation, provide a value for the name parameter in the query string, and then click on the Send button. You can able to see, we got the expected output with the proper response code without any issues.

You can also test the Azure Function in another way inside the Azure Portal. Click on the Code + Test link from the left side to see the function. JSON code. Click on the Test/Run button from the top. Now, you can choose the HTTP method and provide the value for the Parameter in the Body on the Input window and then click on the Run button.

Now you can see, On the Output window, we got the expected output with the proper HTTP response code as below

This is how to Deploy the Azure function app from Visual Studio code using the above-mentioned steps.
Create Azure Function with PowerShell
We discussed above how to create Azure Functions using C#. We can also able to create Azure Function using PowerShell. As part of this functionality, we must perform the below activities.
- Need to create a resource group using the PowerShell cmdlet.
- Then, we will create a storage account that is the container for all the elements. Using the PowerShell cmdlet
- We need to get the storage account connection string from the Azure Portal using the PowerShell cmdlet.
- The next is to create a function app using the PowerShell script.
- Now we need to Set the function app settings.
- Finally, we need to deploy the function into the Azure Portal.
Login To Azure
The first step is to log in to Azure using PowerShell with the Login-AzureRmAccount PowerShell command.
PS C:\WINDOWS\system32> Login-AzureRmAccountNow it will prompt you to enter your Azure Credentials. So enter the username and password and then click on the Sign In button.

Create Azure Resource Group using PowerShell
The next step is to create the Resource Group. Resource groups act as a container for all the elements. We need to use the below PowerShell cmdlet to create the Azure Resource Group using the PowerShell cmdlet.
$myResourceGroup= 'demofunctiongrp'
$mylocation = 'eastus'
$rsgGrp = Get-AzureRmResourceGroup -Name $myResourceGroup -ErrorAction SilentlyContinue
if (-not $rsgGrp) {
$rsgGrp = New-AzureRmResourceGroup -Name $myResourceGroup -Location $mylocation
}
Create Azure Storage Account using PowerShell
The next thing we need is an Azure Storage account. So, use the below PowerShell script to create the Azure Storage Account.
$myStorageAccount = "FunctionDemoStrg123"
$Sku = 'Standard_LRS'
$Paramsstrg = @{
ResourceGroupName = $myResourceGroup
AccountName = $myStorageAccount
Location = $mylocation
SkuName = $Sku
}
$mystrgAccount = New-AzureRmStorageAccount @Paramsstrg
Retrieve the storage account connection string from the Azure Portal
Now we need to retrieve the storage account connection string from the Azure Portal that we need to access the Storage account which we need to store the Azure Function Code.
$mystrgacntKey = Get-AzureRmStorageAccountKey -ResourceGroupName $myResourceGroup -AccountName $myStorageAccount |
Where-Object {$_.KeyName -eq 'Key1'} | Select-Object -ExpandProperty Value
$mystorageacntconstng = "DefaultEndpointsProtocol=https;AccountName=$myStorageAccount;AccountKey=$mystrgacntKey"
Create Azure Function App using PowerShell
Now the next step is to create the Azure Function App using the below PowerShell cmdlet.
$MyNewfunctionApp = 'MyNewAzureDemoFunction'
$Params = @{
ResourceType = 'Microsoft.Web/Sites'
ResourceName = $MyNewfunctionApp
Kind = 'functionapp'
Location = $mylocation
ResourceGroupName = $myResourceGroup
Properties = @{}
Force = $true
}
$MuAzureFunctionApp = New-AzureRmResource @Params 
Apply the settings for the Function App
Now we need to Set the function app settings.
$newAppSettings = @{
AzureWebJobDashboard = $mystorageacntconstng
AzureWebJobsStorage = $mystorageacntconstng
FUNCTIONS_EXTENSION_VERSION = '~1'
WEBSITE_CONTENTAZUREFILECONNECTIONSTRING = $mystorageacntconstng
WEBSITE_CONTENTSHARE = $myStorageAccount
}
$paramsdem = @{
Name = $MyNewfunctionApp
ResourceGroupName = $myResourceGroup
AppSettings = $newAppSettings
}
$mywebApplicatn = Set-AzureRmWebApp @paramsdem
Deployment of the Azure Function
Now we will deploy the Azure Function in Azure Portal using the below PowerShell cmdlet.
$mynewfunctionName = 'MyNewFunctionpro'
$mynewfunctionContent = Get-Content ./HelloWorld/run.ps1 -raw
$mynewfunctionSettings = Get-Content ./myNewFunctionpro/function.json |ConvertFrom-Json
$mynewfunctionRSID = '{0}/functions/{1}' -f $MuAzureFunctionApp.resourceid, $mynewfunctionName
$mynewfunctionProp =@{
config = @{bindings = $mynewfunctionSettings.bindings
}
files = @{
'run.ps1' = "$mynewfunctionContent"
}
}
$Params = @{
ResourceID = $mynewfunctionRSID
Properties = $mynewfunctionProp
Apiversion = '2015-08-01'
Force = $true
}
$function = New-AzureRmResource @Params
This is how we can create and deploy the Azure Function using the PowerShell cmdlet.
Now after the deployment, you can also Edit existing Azure Function in Visual Studio Code.
You may also like the following articles
Conclusion
Well, In this article, we discussed, How To Create Azure Functions In Visual Studio Code, Build Azure functions in Visual Studio Code, and then discuss Run Azure functions locally using Visual Studio Code, and then finally, we discussed the steps to Deploy Azure functions from Visual Studio code, and Create Azure Function with PowerShell. Hope you have enjoyed this article !!!
I am Bijay, a Microsoft MVP (10 times) having more than 17 years of experience in the software industry. During my IT career, I got a chance to share my expertise in SharePoint and Microsoft Azure, like Azure VM, Azure Active Directory, Azure PowerShell, etc. I hope you will learn from these Azure tutorials. Read more
