Skip to content

Instantly share code, notes, and snippets.

@Francisco-Gamino
Last active September 23, 2024 13:21
Show Gist options
  • Save Francisco-Gamino/73fbb67a67f13928df69974b7b9853c7 to your computer and use it in GitHub Desktop.
Save Francisco-Gamino/73fbb67a67f13928df69974b7b9853c7 to your computer and use it in GitHub Desktop.
Az.Functions - Managing Azure Functions via PowerShell.
# Managing Azure Functions via PowerShell Cmdlets
# Prerequisites:
# - PowerShell Core 6 or greater --> https://github.com/PowerShell/PowerShell/releases
# - Core Tools --> https://github.com/Azure/azure-functions-core-tools#installing
# - Az.Functions preview module --> https://www.powershellgallery.com/packages/Az.Functions/0.0.2-preview

# Install Azure Functions PowerShell core module
Install-Module -Name Az.Functions -AllowPrerelease

# See what cmdlets you have available
Get-Command -Module Az.Functions

# Function app creation flow
$subscriptionId = "<your subcription id>"
$resourceGroupName = "Frangom-West-Europe-Win-Premium"
$location = "West Europe"
$storageAccountName = "frangomwinstorage"
$planName = "Frangom-Win-Premium"
$functionAppName = "Frangom-PS-Premium-Demo"

# Create resource group and storage account
Write-Host "Creating resource group '$resourceGroupName' in '$location'." -ForegroundColor Yellow
New-AzResourceGroup -Name $resourceGroupName -Location $location -Force

# Create storage account
Write-Host "Creating storage account '$storageAccountName'." -ForegroundColor Yellow
New-AzStorageAccount -ResourceGroupName $resourceGroupName -AccountName $storageAccountName -Location $location -SkuName Standard_GRS

# 1) Create a Premium plan
# Get the location where Premium is available for Windows
Get-AzFunctionAppAvailableLocation -PlanType Premium -OSType Windows

# Create Premium plan with burst out capability up to 10 instances
Write-Host "Creating Premium plan '$planName'." -ForegroundColor Yellow
New-AzFunctionAppPlan -ResourceGroupName $resourceGroupName `
                      -Name $planName `
                      -Location $location `
                      -MinInstances 1 `
                      -MaxBurst 10 `
                      -Sku EP1 `
                      -WorkerType Windows

# Check to make sure the service plan was created
Get-AzFunctionAppPlan

# Additional filtering options: 
# Filter by Location, ResourceGroupName, and SubscriptionId
# Get-AzFunctionAppPlan -Location "Central US"
# Get-AzFunctionAppPlan  -ResourceGroupName "ResourceGroupName"
# Get-AzFunctionAppPlan -SubscriptionId <subscriptionId 1>, <subscriptionId 1>

# Create function app hosted in a Premium plan
Write-Host "Creating function app '$functionAppName'." -ForegroundColor Yellow
New-AzFunctionApp -Name $functionAppName `
                  -ResourceGroupName $resourceGroupName `
                  -PlanName $planName `
                  -StorageAccount $storageAccountName `
                  -Runtime PowerShell

# Create function app in a consumption plan
Write-Host "Creating function app '$functionAppName'." -ForegroundColor Yellow
New-AzFunctionApp -Name $functionAppName `
                  -ResourceGroupName $resourceGroupName `
                  -Location <Location> `
                  -StorageAccount $storageAccountName `
                  -Runtime PowerShell

# Get all the function apps
Get-AzFunctionApp

# Additional filtering options: 
# Filter by Location, ResourceGroupName, and SubscriptionId
# Get-AzFunctionApp -Location "Central US"
# Get-AzFunctionApp -ResourceGroupName "ResourceGroupName"
# Get-AzFunctionApp -SubscriptionId <subscriptionId 1>, <subscriptionId 1>

# Start, Stop, Restart function app
Get-AzFunctionApp | Stop-AzFunctionApp -Force
Get-AzFunctionApp | Start-AzFunctionApp

# Delete a function app
#  Get-AzFunctionApp -Name <AppName> -ResourceGroupName <ResourceGroupName> | Remove-AzFunctionApp -Force

# Delete a function app plan
#  Get-AzFunctionAppPlan -Name <AppName> -ResourceGroupName <ResourceGroupName> | Remove-AzFunctionAppPlan -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment