PowerShell Function App is failing to import Microsoft.PowerApps.Administration.PowerShell Module

Mayank Gupta 1 Reputation point
2023-04-01T18:55:47.05+00:00

I am trying to import the "Microsoft.PowerApps.Administration.PowerShell" module in my PowerShell Azure Function App. The import is successful but the following command in my "run.ps1" file is throwing an error:

Add-PowerAppsAccount -Username $username -Password $pass

Error.txt

Following are the contents of function.json:

{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "Request",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "Response"
    }
  ]
}

Following are the contents of host.json:

{
  "version": "2.0",
  "managedDependency": {
    "Enabled": true
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[3.*, 4.0.0)"
  }
}

The error was pretty big so I have mentioned it in the attached file (Error.txt)

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,679 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,329 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Limitless Technology 44,121 Reputation points
    2023-04-03T12:42:28.7533333+00:00

    Hello there,

    The workaround is to update the runtime version to 3.8.2.0 by updating the FUNCTION_EXTENSION_VERSION in the application configuration of your function app if you are running PowerShell function version 7.

    You can find similar discussion here

    https://learn.microsoft.com/en-us/answers/questions/919927/powershell-function-app-fails-to-import-module

    Hope this resolves your Query !!

    --If the reply is helpful, please Upvote and Accept it as an answer--

    0 comments No comments

  2. MuthuKumaranMurugaachari-MSFT 22,276 Reputation points
    2023-04-05T15:49:58.19+00:00

    Mayank Gupta Thanks for posting your question in Microsoft Q&A. Based on the description above and the error details, I assume you have added the module in requirements.psd1 as shown below and used FUNCTIONS_WORKER_RUNTIME_VERSION as 7.2 or greater.

    @{
        'Microsoft.PowerApps.Administration.PowerShell' = '2.0.156'
    }
    

    When I test the code, I got the same error as you observed. User's image

    You need to include -UseWindowsPowershell while importing the older modules and more details are discussed in this thread: Validate PS7 Import-Module -UseWindowsPowerShell in Azure Functions cloud environment. This should mitigate the issue and let me know if you face any issues.

    Import-Module -Name Microsoft.PowerApps.Administration.PowerShell -UseWindowsPowershell
    

    If you found the answer to your question helpful, please take a moment to mark it as "Yes" for others to benefit from your experience. Or simply add a comment tagging me and would be happy to answer your questions.

    0 comments No comments