Update Azure Function extension bundle with PowerShell

Update Azure Function extension bundle with PowerShell

Hi All,

Recently i did get a lot of Mails from Microsoft, to update the exension bundle for my Azure Functions.

The following Microsoft Learn Website shows the supported Versions of the Extension Bundle

Sadly the Upgrade extension bundles does not give any advice how to do that excactly nor a Script or commands that would update it 🙁

Using the Azure Portal, i can see that there is a Notification on the Azure Function for the Extension Bundle

If you look at the Azure Function > App Files > hosts.json you can view and edit the Version of the Extension Bundle.

One easy way change it here and hit “Save”

PowerShell

But i want to do that with the AZ PowerShell Module

Connect to Azure with AZ PowerShell

# Connect to Azure with AZ PowerShell Module
Connect-AzAccount -Tenant icewolfch.onmicrosoft.com

List Subscriptions

# List Subscriptions
Get-AzSubscription -TenantId "46bbad84-29f0-4e03-8d34-f6841a5071ad"

List Function Apps in that Subscription

# List Function Apps
$AZFunctonApps = Get-AzFunctionApp -WarningAction SilentlyContinue
$AZFunctonApps

I just dig around in the dirt to figure out how i could archieve my goal.

List Function App Details

# List Function App
$FunctionAppName = "IRGENDWOIMINTERNET-MTASTS"
$RGName = "RG_MTASTS2" 
Get-AzFunctionApp -Name $FunctionAppName -ResourceGroupName $RGName | fl

List Function App Settings - we kind of see something here - but that’s not the Format we are looking for.

# List Function App Setting
$FunctionAppName = "IRGENDWOIMINTERNET-MTASTS"
$RGName = "RG_MTASTS2" 
Get-AzFunctionAppSetting -Name $FunctionAppName -ResourceGroupName $RGName | fl

I’ve checked in the Azure Portal with the Developer Tools

Here is what i was coming up with in PowerShell

###############################################################################
# Get host.json from via Management Azure
###############################################################################
$SubscriptionID = "42ecead4-eae9-4456-997c-1580c58b54ba"
$RGName = "RG_MTASTS2"
$FunctionAppName = "IRGENDWOIMINTERNET-MTASTS"
$uri = "https://management.azure.com/subscriptions/$SubscriptionID/resourceGroups/$RGName/providers/Microsoft.Web/sites/$FunctionAppName/hostruntime/admin/vfs//host.json?relativePath=1&api-version=2022-03-01"

$Token = (Get-AzAccessToken -ResourceUrl "https://management.azure.com").Token
$AccessToken = ConvertFrom-SecureString $Token -AsPlainText
$headers = @{ Authorization = "Bearer $AccessToken" }
$Result = Invoke-WebRequest -Uri $URI -Method "GET" -headers $headers
$result.Content

To be honest, i played around with Copilot and it directed me in this way

###############################################################################
# Get host.json from via SCM
###############################################################################
$RGName = "RG_MTASTS2"
$FunctionAppName = "IRGENDWOIMINTERNET-MTASTS"

# Get a token for the Kudu (SCM) site
$Token = (Get-AzAccessToken -ResourceUrl "https://management.azure.com").Token
$AccessToken = ConvertFrom-SecureString $Token -AsPlainText
$headers = @{ Authorization = "Bearer $AccessToken" }

# Kudu VFS endpoint to host.json
$scmBase = "https://$FunctionAppName.scm.azurewebsites.net"
$vfsHost = "$scmBase/api/vfs/site/wwwroot/host.json"

#TEXT with Invoke-WebRequest
$hostJsonText = Invoke-WebRequest -Uri $vfsHost -Headers $headers -Method "GET"
$hostJsonText.Content

#JSON with Invoke-RestMethod
$hostJsonText = Invoke-RestMethod -Uri $vfsHost -Headers $headers -Method "GET"
$hostJsonText

Now we got what we needed and here is the Function to update the ExtensionBundle of an Azure Function

The Script Update-AZFunctionExtensionBundle is also available on my GitHub Repo.

###############################################################################
# Update AzureFunction ExtensionBundle Version
# 2025-11-25 Initilial Version - Andres Bohren - https://blog.icewolf.ch
###############################################################################
Function Update-AZFunctionExtensionBundle {
    param(
        [Parameter(Mandatory=$true)] [string] $ResourceGroup,
        [Parameter(Mandatory=$true)] [string] $FunctionAppName,
        [Parameter(Mandatory=$false)] [string] $ExtensionBundleVersion = "[4.0.0, 5.0.0]"
    )

    # Get a token for the Kudu (SCM) site
    $Token = (Get-AzAccessToken -ResourceUrl "https://management.azure.com").Token
    $AccessToken = ConvertFrom-SecureString $Token -AsPlainText
    $headers = @{ Authorization = "Bearer $AccessToken" }

    # Kudu VFS endpoint to host.json
    $scmBase = "https://$FunctionAppName.scm.azurewebsites.net"
    $vfsHost = "$scmBase/api/vfs/site/wwwroot/host.json"

    # Initialize Variable
    $hostJsonText = $null

    try {
        #Read current host.json (if it exists)
        $hostJsonText = Invoke-RestMethod -Uri $vfsHost -Headers $headers -Method "GET" -ErrorAction Stop 
        $hostJsonText
        #Change ExtensionBundleVersion
        $hostJsonText.extensionBundle.version = $ExtensionBundleVersion

        # Serialize
        $body = $hostJsonText | ConvertTo-Json -Depth 20
        $bytes = [System.Text.Encoding]::UTF8.GetBytes($body)

        # Write back (overwrite) via Kudu VFS
        Invoke-RestMethod `
        -Uri $vfsHost `
        -Headers @{ Authorization = "Bearer $AccessToken"; "If-Match" = "*"} `
        -Method "PUT" `
        -Body $bytes `
        -ContentType "application/octet-stream"

        Write-Host "Updated $FunctionAppName host.json extensionBundle to $DesiredBundleRange" -ForegroundColor Green

        } catch {
            Write-Host "Failed to update $FunctionAppName host.json extensionBundle" -ForegroundColor Red
        }
}

#Call the Function
$RGName = "RG_MTASTS2"
$FunctionAppName = "IRGENDWOIMINTERNET-MTASTS"
Update-AZFunctionExtensionBundle -ResourceGroup $RGName -FunctionAppName $FunctionAppName

As you can see in the Portal - it did work

Hope this helps others to update the Azure Function Extension Bundle and don’t have to spend several hours like me to figure this out.

Regards
Andres Bohren

Azure Logo

PowerShell Logo