The Function app may be missing a module containing the 'Connect-MgGraph' command definition

Liju P Nandanan 21 Reputation points
2023-02-05T16:04:29.8766667+00:00

I am trying to run a Microsoft Graph PowerShell script through azure PowerShell function. But I am getting following error

The Function app may be missing a module containing the 'Connect-MgGraph' 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

The Function app may be missing a module containing the 'Connect-MgGraph' command definition. If this command belongs to a module available on the PowerShell Gallery, add a reference to this module to requirements.psd1

I am using following code in azure PowerShell function

Connect-MgGraph -ClientId "client id" -TenantId "tenantid" -CertificateThumbprint "thumbprint"

Does the Microsoft graph ps script only works in Windows powershell? Is there any reference i can add to use this in azure function app

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,195 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,512 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,676 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MughundhanRaveendran-MSFT 12,481 Reputation points
    2023-02-06T13:41:37.5466667+00:00

    @Liju P Nandanan ,

    From the error message, it appears that you are missing the "Microsoft.Graph" powershell module in the Azure function. To add the module, please follow the below steps

    1. Select App files in the Azure Functions portal
    2. Select requirements.psd1 file in the drop down list
    3. Add the module as mentioned below User's image

    There is no need to add install module command in the script as Azure functions use dependency management to add modules to the script. Once you have added the module in the requirements.psd1 file, run the script. When you run the script, you should see a message stating that the module is downloaded.

    Hope this helps!

    1 person found this answer helpful.

  2. Limitless Technology 44,421 Reputation points
    2023-02-07T16:43:33.22+00:00

    Hi. Thank you for your question and reaching out. I’d be more than happy to help you with your query

    Yes, to fix this, you need to install the Microsoft.Graph PowerShell module from the PowerShell Gallery. To do this, open a PowerShell session and run the following command:

    Install-Module Microsoft.Graph

    Once the module has been installed, you will need to add a reference to the module in your requirements.psd1 file. To do this, open the requirements.psd1 file in a text editor and add the following line:

    Microsoft.Graph

    Once you have done that, save the file, and you should be all set. You can now use the Connect-MgGraph command in your PowerShell Function.

    If the reply was helpful, please don’t forget to upvote or accept as answer, thank you.


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.