Search code examples
azure-functionsmicrosoft-graph-sdks

Azure Function App - Microsoft Graph modules could not be loaded


I have an Azure Function App running powershell script. I use Connect-MgGraph cmdlet to connect to Microsoft graph API but its failing with error as -

"**ERROR: The 'Connect-MgGraph' command was found in the module 'Microsoft.Graph.Authentication', but the module could not be loaded**. For more information, run 'Import-Module Microsoft.Graph.Authentication'"

Can someone help resolve the error please ?

I have all the Graph modules available in Managed-dependency folder for this app. Also, I have also already added below required Modules as dependency management in Requirements.psd1.

'Microsoft.Graph' = '2.1.0'
'Microsoft.Graph.Authentication' = '2.1.0'

Also, tried to run Import-Module Microsoft.Graph.Authentication explicitly in run.ps1 and through profile.ps1 but its not executed correctly


Solution

  • Use these commands in run.ps1 to connect to Microsoft graph:

    Import-Module  -Name Microsoft.Graph
    
    Connect-MgGraph
    

    requirements.ps1:

    @{
    
    'Microsoft.Graph'  =  '2.2.0'
    
    }
    

    enter image description here

    enter image description here

    enter image description here