Importing Powershell module into Function is Failing....

james bennett 51 Reputation points
2021-08-15T15:35:19.733+00:00

I have an Azure function that is running PowerShell. I'm trying to write to an Azure database. Testing this locally is working but when I've moved into azure I'm having problems importing the AZ.SQL module that the code requires.

Things I've tried:

1: Enabling Managed Dependency but adding this to the Host.json file:

                           "managedDependency": {  
    "Enabled": true  
  }  

The error I get from the above when I add into Visual Studio Code is "Property managedDependency is not allowed".

Documentation clearly states that by enabling this should allow, providing the requirements.psd1 file has the following entry in: ' 'Az ' = '6.*'' which I have too.

https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-powershell?tabs=portal#dependency-management.

2: Uploading the az.sql module into the module folder inside the Function app which should apparently do the same thing. This is also failing. I've been following this article - https://tech.nicolonsky.ch/azure-functions-powershell-modules/

I can't find any other information and have hit a wall.
The error I'm getting in my function app is this:

2021-08-15T15:19:23.156 [Information] INFORMATION: PowerShell HTTP trigger function processed a request.
2021-08-15T15:19:23.227 [Information] INFORMATION:
2021-08-15T15:19:26.713 [Warning] The Function app may be missing a module containing the 'Invoke-Sqlcmd' command definition. If this command belongs to a module available on the PowerShell Gallery, add a reference to this module to requirements.psd1. Make sure this module is compatible with PowerShell 7. For more details, see https://aka.ms/functions-powershell-managed-dependency. If the module is installed but you are still getting this error, try to import the module explicitly by invoking Import-Module just before the command that produces the error: this will not fix the issue but will expose the root cause.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Answer accepted by question author
  1. MayankBargali-MSFT 70,996 Reputation points Moderator
    2021-08-16T03:08:27.25+00:00

    @james bennett As per the error message Invoke-Sqlcmd command was not found. The Invoke-Sqlcmd command is part of SqlServer module.
    Looks like you have only define the only the Az module in your requirements.psd1 file.

    The Az module does have the Az.Sql dependent module but no SqlServer module. You need to updated your requirements.psd1 file with SqlServer module.

    Note: When you update the requirements.psd1 file, updated modules are installed after a restart as mentioned in the document.

    requirements.psd1

    @{  
    	Az = '6.*'  
        SqlServer = '21.1.18147'  
    }  
    

0 additional answers

Sort by: Most helpful

Your answer

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