-
-
Save JustinGrote/d751dd1b05ef0db35921da01e375a5ab to your computer and use it in GitHub Desktop.
function New-AzFunction { | |
[CmdletBinding(SupportsShouldProcess)] | |
param( | |
[Parameter(Mandatory)][String]$Name, | |
[ValidateSet( | |
"Azure Blob Storage trigger", | |
"Azure Cosmos DB trigger", | |
"Azure Event Grid trigger", | |
"Azure Event Hub trigger", | |
"HTTP trigger", | |
"IoT Hub (Event Hub)", | |
"Azure Queue Storage trigger", | |
"SendGrid", | |
"Azure Service Bus Queue trigger", | |
"Azure Service Bus Topic trigger", | |
"SignalR negotiate HTTP trigger", | |
"Timer trigger" | |
)][String]$Template = 'HTTP Trigger', | |
[String]$Language = 'Powershell' | |
) | |
if ($PSCmdlet.ShouldProcess($pwd,"Creating $Language $Template function $Name")) { | |
$funcExe = (Get-Command func -Type 'Application' -ErrorAction stop).Source | |
& $funcExe new --language $Language --template $Template --name $Name | |
} | |
} |
iwr https://gist.githubusercontent.com/JustinGrote/d751dd1b05ef0db35921da01e375a5ab/raw/db01d9a124ce22bf45ff29004be7030faad9389b/New-AzFunction.ps1 | iex
New-AzFunction
Run it in the folder you want to start your new azure function and specify the name. It will create an HTTPTrigger by default. You can also tab through the -Template parameter to select a template other than http trigger.
Here's one that will work with no prompting
New-AzFunction -Name MyTestFunction -Template 'SendGrid'
Also supports -whatif
New-AzFunction -Name TestFunction2 -Whatif
Name Value
PSVersion 6.2.3
PSEdition Core
GitCommitId 6.2.3
OS Microsoft Windows 10.0.19041
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
There was an error running the code
And then executing the function.
Shouldn't there be a way to specify the Plan and FunctionApp names? I'm trying to create the new Function directly in the Azure Plan instead of any local copy.
The below code creates a consumption Plan and a FunctionApp in the consumption plan.
New-AzAppServicePlan -Name <> -Location eastus -ResourceGroupName test -Tier Y1 -Verbose
New-AzFunctionApp -OSType Windows -Runtime PowerShell -ResourceGroupName test -Name <> -StorageAccountName <> -PlanName <> -SubscriptionId <> -DisableApplicationInsights
The first error is a psreadline error, please install powershell preview extension for vscode.
The second error is because I assumed there would be only one "func" installed on your system
This command is for creating local functions for development. For deployment you may want to check out the Azure Functions Vscode extension.
Could you share an example?