title | description | ms.topic | ms.date | ms.devlang | ms.custom |
---|---|---|---|---|---|
Create a PowerShell function using Visual Studio Code - Azure Functions |
Learn how to create a PowerShell function, then publish the local project to serverless hosting in Azure Functions using the Azure Functions extension in Visual Studio Code. |
quickstart |
06/03/2024 |
powershell |
mode-api, vscode-azure-extension-update-complete |
[!INCLUDE functions-language-selector-quickstart-vs-code]
In this article, you use Visual Studio Code to create a PowerShell function that responds to HTTP requests. After testing the code locally, you deploy it to the serverless environment of Azure Functions.
Completing this quickstart incurs a small cost of a few USD cents or less in your Azure account.
There's also a CLI-based version of this article.
Before you get started, make sure you have the following requirements in place:
[!INCLUDE functions-requirements-visual-studio-code-powershell]
[!INCLUDE functions-install-core-tools-vs-code]
In this section, you use Visual Studio Code to create a local Azure Functions project in PowerShell. Later in this article, you'll publish your function code to Azure.
-
In Visual Studio Code, press F1 to open the command palette and search for and run the command
Azure Functions: Create New Project...
. -
Choose the directory location for your project workspace and choose Select. You should either create a new folder or choose an empty folder for the project workspace. Don't choose a project folder that is already part of a workspace.
-
Provide the following information at the prompts:
Prompt Selection Select a language for your function project Choose PowerShell
.Select a template for your project's first function Choose HTTP trigger
.Provide a function name Type HttpExample
.Authorization level Choose Anonymous
, which enables anyone to call your function endpoint. For more information, see Authorization level.Select how you would like to open your project Choose Open in current window
.Using this information, Visual Studio Code generates an Azure Functions project with an HTTP trigger. You can view the local project files in the Explorer. To learn more about files that are created, see Generated project files.
[!INCLUDE functions-run-function-test-local-vs-code]
After you've verified that the function runs correctly on your local computer, it's time to use Visual Studio Code to publish the project directly to Azure.
[!INCLUDE functions-sign-in-vs-code]
[!INCLUDE functions-publish-project-vscode]
[!INCLUDE functions-vs-code-run-remote]
[!INCLUDE functions-cleanup-resources-vs-code.md]
You have used Visual Studio Code to create a function app with a simple HTTP-triggered function. In the next article, you expand that function by connecting to Azure Storage. To learn more about connecting to other Azure services, see Add bindings to an existing function in Azure Functions.
[!div class="nextstepaction"] Connect to an Azure Storage queue