admin管理员组

文章数量:1122832

I have a PowerShell script that I want to run in a function app, but when I run the script for testing it starts downloading the dependencies then I get this error:

FailureException: Failed to install function app dependencies. Error: 'Failed to install function app dependencies. Error: 'The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Unable to save the module 'Az'.''Stack: at Microsoft.Azure.Functions.PowerShellWorker.DependencyManagement.DependencyManager.WaitOnDependencyInstallationTask()

I can't tell why it is failing to install the dependencies. For more context here is my host.JSON file:

{
    "version":"2.0",
    "functionTimeout":"00:10:00",
    "managedDependency":{
        "enabled":true
        },
    "extensionBundle":{
        "id":"Microsoft.Azure.Functions.ExtensionBundle",
        "version":"[4.*, 5.0.0)"
        }
        }

Here is my requirements.psd1:

# This file enables modules to be automatically managed by the Functions service.
# See  for additional information.
#
@{
    # For latest supported version, go to ''. 
    # To use the Az module in your function app, please uncomment the line below.
    'Az' = '13.*'
    'PnP.PowerShell' = '2.12.0'
}

I imported the modules as well in my script, and I checked the files in my kudu sometimes it installs some modules from the az library but are missing a lot sometimes it fails completely and the kudu displays only the requirements.psd1 file.

I have a PowerShell script that I want to run in a function app, but when I run the script for testing it starts downloading the dependencies then I get this error:

FailureException: Failed to install function app dependencies. Error: 'Failed to install function app dependencies. Error: 'The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Unable to save the module 'Az'.''Stack: at Microsoft.Azure.Functions.PowerShellWorker.DependencyManagement.DependencyManager.WaitOnDependencyInstallationTask()

I can't tell why it is failing to install the dependencies. For more context here is my host.JSON file:

{
    "version":"2.0",
    "functionTimeout":"00:10:00",
    "managedDependency":{
        "enabled":true
        },
    "extensionBundle":{
        "id":"Microsoft.Azure.Functions.ExtensionBundle",
        "version":"[4.*, 5.0.0)"
        }
        }

Here is my requirements.psd1:

# This file enables modules to be automatically managed by the Functions service.
# See https://aka.ms/functionsmanageddependency for additional information.
#
@{
    # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. 
    # To use the Az module in your function app, please uncomment the line below.
    'Az' = '13.*'
    'PnP.PowerShell' = '2.12.0'
}

I imported the modules as well in my script, and I checked the files in my kudu sometimes it installs some modules from the az library but are missing a lot sometimes it fails completely and the kudu displays only the requirements.psd1 file.

Share Improve this question asked yesterday confusedJuniorconfusedJunior 1 New contributor confusedJunior is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 3
  • Provide your function code. – Pravallika KV Commented yesterday
  • @PravallikaKV isnt it irrelevant tho? i want to protect my company data and here my problem isnt about the script itself but about downloading the dependencies from the requirements file – confusedJunior Commented 9 hours ago
  • Check if my below provided answer helps. – Pravallika KV Commented 9 hours ago
Add a comment  | 

2 Answers 2

Reset to default 0

Create an Azure function app with Premium Pricing Plan and Runtime stack Powershell 7.4 version .

requirements.ps1:

@{
     'Az' = '13.*'
     'PnP.PowerShell' = '2.12.0'
}

host.json:

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

Deployed the function to Azure:

Able to run the deployed function in Portal successfully:

2025-01-07T07:01:56Z   [Verbose]   AuthenticationScheme: WebJobsAuthLevel was successfully authenticated.
2025-01-07T07:01:56Z   [Verbose]   AuthenticationScheme: Bearer was not authenticated.
2025-01-07T07:01:56Z   [Verbose]   Authorization was successful.
2025-01-07T07:01:56Z   [Information]   Executing 'Functions.HttpTrigger' (Reason='This function was programmatically called via the host APIs.', Id=2a08447d-fa97-4322-9a6a-6112dbc62e3f)
2025-01-07T07:01:56Z   [Verbose]   Sending invocation id: '2a08447d-fa97-4322-9a6a-6112dbc62e3f
2025-01-07T07:01:56Z   [Verbose]   Posting invocation id:2a08447d-fa97-4322-9a6a-6112dbc62e3f on workerId:fe54a398-cf82-48e5-90bc-b871e0222496
2025-01-07T07:01:56Z   [Information]   INFORMATION: PowerShell HTTP trigger function processed a request.
2025-01-07T07:01:57Z   [Information]   Executed 'Functions.HttpTrigger' (Succeeded, Id=2a08447d-fa97-4322-9a6a-6112dbc62e3f, Duration=400ms)

in the requirements.psd1 file i commented the line #'Az' = '13.*' then used import-module Az in my script which seemed to solve the problem for now but azure says it is just a temporary solution and preferrably import the module in the requirements in the file but if it gets buggy and the error persists (my case) resort to the method i did

本文标签: powershellFailureException Failed to install function app dependenciesStack Overflow