Share via

Powershell script in Azure Function code

Khandu Shinde 150 Reputation points
2025-05-14T06:05:42.7633333+00:00

Hi All

I have a PowerShell script that connects to Microsoft Graph to retrieve user details and stores the information in a storage account. The script runs successfully on my local machine, but when I deploy it to an Azure Function, it throws the following error:

Connect-MgGraph : The term 'Connect-MgGraph' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. at run.ps1

Please help me resolve this concern.

Azure Functions
Azure Functions

An Azure service that provides an event-driven serverless compute platform.


1 answer

Sort by: Most helpful
  1. Anonymous
    2025-06-11T11:29:53.95+00:00

    @Khandu Shinde ,

    Thanks for reaching out.

    The error you're seeing (Connect-MgGraph : The term 'Connect-MgGraph' is not recognized...) usually means that the Microsoft Graph PowerShell SDK isn't available in the Azure Function environment.

    To fix this, you can add a requirements.psd1 file to your Function App with the following content:

    
    @{
        'Microsoft.Graph' = '2.*'
    }
    

    Azure Functions will automatically download and install the module when it starts, as long as managed dependencies are enabled (which is the default). There's no need to manually install the module unless you're testing locally.

    Also, make sure your function is running on PowerShell 7 since the Graph SDK requires it. If you're using Connect-MgGraph -Identity, please ensure that the Function App’s Managed Identity has the right permissions in Azure AD (like User.Read.All).

    0 comments No comments

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.