When setting requirements.psd1 for Azure Function. Function fails before script execution.

Chris Shockey 0 Reputation points
2025-04-10T18:34:37.1266667+00:00

This is the error I'm getting (when not setting the requirements.psd1, the Azure function runs as expected, but saying the dependencies are required, of course):

025-04-10T18:09:48Z [Information] Executing 'Functions.MyFunctionNameScrubbed' (Reason='This function was programmatically called via the host APIs.', Id=xxxxx)
2025-04-10T18:09:48Z [Verbose] Sending invocation id: 'xxx
2025-04-10T18:09:48Z [Verbose] Posting invocation id:844e4dcf-dc6b-45f1-8a55-c6a213efe46b on workerId:9c04b4bf-537a-48e5-9429-32ee2e145aa2
2025-04-10T18:09:48Z [Error] Executed 'Functions.MyFunctionNameScrubbed' (Failed, Id=844e4dcf-dc6b-45f1-8a55-c6a213efe46b, Duration=8ms)

These are my requirements.psd1 file setting (inlcuding commented lines I've tried with no success):

@{
    # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. Uncomment the next line and replace the MAJOR_VERSION, e.g., 'Az' = '5.*'
    'Az.Accounts' = '4.1.0'
    'Az.Storage'  = '8.3.0'
    #'Az.Storage' = 'latest'
    # 'Az' = '13.*'
    # 'az' = 'latest'
    # 'Az.Accounts' = 'latest'
    # 'Az.Storage' = 'latest'

}

My Hosts.json (showing managedDependency is set)

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
    "managedDependency": {
    "enabled": true
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  }

}

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME_VERSION": "7.4",
    "FUNCTIONS_WORKER_RUNTIME": "powershell"
  }
}

I have tried just importing modules instead, but this is an ugly solution as it needs to download the file every time the function runs. This has never worked. I have three working functions that all run fine (HTTP triggers), but in this particular function, I need az.storage and want to transition to managed accounts via az.accounts.

Any help would be greatly appreciated.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,677 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Shireesha Eeraboina 2,815 Reputation points Microsoft External Staff
    2025-04-11T07:10:21.55+00:00

    Hi Chris Shockey,

    Thanks for sharing the details. The issue likely relates to how Azure Functions handles PowerShell module dependencies. Even though you’ve correctly set requirements.psd1 and enabled managedDependency in host.json, sometimes the modules don’t get restored properly.

    • Ensure the file is named exactly requirements.psd1 and is placed at the root of the Function App.

    Try removing specific versions temporarily, and just use:

    'Az' = '10.*'
    
    

    This ensures all necessary submodules like Az.Accounts and Az.Storage are included.

    • After updating requirements.psd1, restart the Function App to trigger dependency installation.
    • Check the Kudu console (https://<yourfunction>.scm.azurewebsites.net/DebugConsole) under D:\home\data\ManagedDependencies to see if modules were installed.

    To help you better understand, kindly refer to the documentations below:

    https://github.com/Azure/azure-functions-powershell-worker/issues/239

    requirements.psd1 syntax

    Please also check these thread as it will help you identify your issue more easily.

    I hope this addresses your query. Please let me know if you need any further assistance or clarification.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.