Powershell Function App fails to import module

Steven R 56 Reputation points
2022-07-08T17:09:27.307+00:00

Hi all,

We have had a Powershell Function App running hundreds of time a day for the past three years without any issues. Suddenly in the past week, it's failing almost 95% of the time.

The function app now fails when loading the Powershell Module (MSOnline) using the Import-Module cmdlet, like this:

$currentDir = (Get-Location)  
Import-Module "$currentDir\bin\MSOnline\1.1.183.66\MSOnline.psd1" -UseWindowsPowerShell  

This results in the following error:

[Error] ERROR: Failed to generate proxies for remote module 'MSOnline'. The -OutputModule parameter does not resolve to a path, and a user module path cannot be found for the provided name.Exception :Type : System.InvalidOperationExceptionMessage : Failed to generate proxies for remote module 'MSOnline'. The -OutputModule parameter does not resolve to a path, and a user module path cannot be found for the provided name

Searching the web and these forums does not give me any more insight to what this might mean. The -OutputModule is not a flag for the Import-Module command.

(The complete stacktrace is available in this gist: https://gist.github.com/stevenrombauts/ac74463a78c278935a457ceb867e9b5f )

What 's even crazier is that it sometimes does work. I can hit the same function app once and get a good result, and the next 10 requests will fail. Once it fails, it seems to keep on failing.

We included the MSOnline files in our function app files directly to improve performance and load it directly from its path. This has always worked fine. For testing today I tried loading it again through requirements.psd1 file and let Azure handle it, but it won't even successfully install the module anymore (this worked about a year ago).

We're running on Function App Runtime ~3, with PowerShell Core 7.0 on 64 bit.

Does anyone have an idea as to what might be going on here?

Many thanks for your help.

Best regards,
Steven

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,016 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,282 questions
0 comments No comments
{count} vote

Accepted answer
  1. MayankBargali-MSFT 67,001 Reputation points
    2022-07-13T04:56:15.503+00:00

    @Steven R Apology for the inconvenience due to this issue. 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.
    The product team will be fixing the issue in the latest runtime.

    Similar Discussion: https://learn.microsoft.com/en-us/answers/questions/920865/index.html

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.

    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. MotoX80 30,916 Reputation points
    2022-07-08T17:44:02.57+00:00

    Check out your PSModulePath.

    ($env:PSModulePath).split(";")  
    

    https://github.com/PowerShell/PowerShell/issues/12532

    It was an issue with PSModulePath. Something put in Windows\System32\WindowsPowerShell\Modules into the PSModulePath. I'm guessing when 7 tried to load utility it loaded 5.1 utility instead and blew up. Fun troubleshooting though. Now need to find root cause.

    0 comments No comments

  2. Steven R 56 Reputation points
    2022-07-09T07:43:46.09+00:00

    Hi @MotoX80 , thanks for your response.

    Looking at the PSModulePath in the function app, I don't immediately see anything that shouldn't be in there. It contains these paths when the Import-Module fails:

    • C:\home\data\ManagedDependencies\2207081450561686137.r (managed dependencies installed automatically)
    • C:\home\site\wwwroot\Modules (empty directory)
    • C:\Program Files (x86)\SiteExtensions\Functions\3.10.2\workers\powershell\7\Modules (Powershell 7 global modules)

    Do you see anything wrong with this?

    Thanks again,
    Steven


  3. Srividya Jagannathan 1 Reputation point
    2022-08-03T18:22:12.53+00:00

    @Steven R @MayankBargali-MSFT I changed the run time as specified and still get the same issue on powershell7 azure functions. Please can you help

    using namespace System.Net

    Input bindings are passed in via param block.

    param($Request, $TriggerMetadata)

    Interact with query parameters or the body of the request.

    Import-Module MsOnline -UseWindowsPowershell
    Import-Module PartnerCenter -UseWindowsPowershell

    ......

    022-08-03T18:07:10Z [Information] Executing 'Functions.HttpTrigger3' (Reason='This function was programmatically called via the host APIs.', Id=be6cd8ad-bb30-4962-9fce-e97d4a125c08)
    2022-08-03T18:07:10Z [Verbose] Sending invocation id:be6cd8ad-bb30-4962-9fce-e97d4a125c08
    2022-08-03T18:07:10Z [Verbose] Posting invocation id:be6cd8ad-bb30-4962-9fce-e97d4a125c08 on workerId:75af6330-6ad2-41bf-9231-0c347a982e3c
    2022-08-03T18:07:17Z [Error] ERROR: Failed to generate proxies for remote module 'MsOnline'. The -OutputModule parameter does not resolve to a path, and a user module path cannot be found for the provided name.

    Exception :
    Type : System.InvalidOperationException
    Message : Failed to generate proxies for remote module 'MsOnline'. The -OutputModule parameter does not resolve to a path, and a user module path cannot be found for the provided name.
    InnerException :
    Type : System.Management.Automation.CmdletInvocationException
    ErrorRecord :
    Exception :
    Type : System.ArgumentException
    Message : The -OutputModule parameter does not resolve to a path, and a user module path cannot be found for the provided name.
    TargetSite :

    0 comments No comments

  4. AllaBasha Shaik 1 Reputation point
    2022-07-25T17:30:33.24+00:00

    @MayankBargali-MSFT

    I am using 7.2 Power Shell Version and even I am facing the issue, Do you recommend to change the FUNCTIONS_EXTENSION_VERSION to 3.8.2.0... Current version updated is ~4... Please Suggest.

    ERROR: Failed to generate proxies for remote module 'PSFive9Admin'. The -OutputModule parameter does not resolve to a path, and a user module path cannot be found for the provided name. Exception : Type : System.InvalidOperationException Message : Failed to generate proxies for remote module 'PSFive9Admin'. The -OutputModule parameter does not resolve to a path, and a user module path cannot be found for the provided name. InnerException : Type : System.Management.Automation.CmdletInvocationException ErrorRecord : Exception : Type : System.ArgumentException Message : The -OutputModule parameter does not resolve to a path, and a user module path cannot be found for the provided name. TargetSite : Name : ThrowTerminatingError DeclaringType : System.Management.Automation.MshCommandRuntime, System.Management.Automation, Version=7.2.4.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35 MemberType : Method Module : System.Management.Automation.dll Source : System.Management.Automation HResult : -2147024809 StackTrace : at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord) TargetObject : Microsoft.PowerShell.Commands.ExportPSSessionCommand CategoryInfo : InvalidArgument: (Microsoft.PowerShel…ortPSSessionCommand:ExportPSSessionCommand) [Export-PSSession], ArgumentException FullyQualifiedErrorId : ExportPSSession_ErrorModuleNameOrPath,Microsoft.PowerShell.Commands.ExportPSSessionCommand InvocationInfo : MyCommand : Export-PSSession HistoryId : 1 InvocationName : Export-PSSession CommandOrigin : Internal ScriptStackTrace : at <ScriptBlock>, C:\home\site\wwwroot\UserOnboarding-new\run.ps1: line 49 TargetSite : Name : Invoke DeclaringType : System.Management.Automation.Runspaces.PipelineBase, System.Management.Automation, Version=7.2.4.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35 MemberType : Method Module : System.Management.Automation.dll Message :

    0 comments No comments