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,929 questions
Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. MughundhanRaveendran-MSFT 12,506 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,766 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.


  3. Chendrayan Venkatesan 11 Reputation points
    2025-06-27T12:28:45.4333333+00:00

    I know this is an old post but just wanted to share my two cents in case it helps someone down the road.

    If your module isn’t being discovered even after correctly updating your requirements.psd1, try this workaround:

    • Create a modules folder in the root directory of your function app.
    • Drop your module inside that folder.
    • Reference the module directly from your function.

    This approach can be a lifesaver when the PowerShell Gallery is unreachable or unreliable during deployment. More details and background here:

    https://about-powershell.com/blog/azure-functions-fails-when-powershell-gallery-is-not-reachable-powershell-worker-runtime/

    Hope this helps someone stuck in a similar situation!

    0 comments No comments

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.