Skip to content

Instantly share code, notes, and snippets.

@JustinGrote
Last active April 5, 2020 14:49
Show Gist options
  • Save JustinGrote/d751dd1b05ef0db35921da01e375a5ab to your computer and use it in GitHub Desktop.
Save JustinGrote/d751dd1b05ef0db35921da01e375a5ab to your computer and use it in GitHub Desktop.
Powershell Azure Function Template Starter
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
}
}
@Ayanmullick
Copy link

Ayanmullick commented Jan 15, 2020

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

image

And then executing the function.

image

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

@JustinGrote
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment