You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Functions中PowerShell模块无法从requirements.psd1加载求助

Azure Functions中PowerShell调用Connect-MgGraph提示未识别的解决办法

在Azure Functions的PowerShell函数里调用Microsoft Graph的Connect-MgGraph cmdlet时,遇到以下错误:

[Error] ERROR: The term 'Connect-MgGraph' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

已配置requirements.psd1文件如下,且host.json中已开启managedDependency:

@{
    # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. Uncomment the next line and replace the MAJOR_VERSION, e.g., 'Az' = '5.*'
    # 'Az' = '10.*'
    'Az.Accounts' = '2.5.4'
    'Microsoft.Graph.Authentication' = '2.*'
}

解决步骤

  • 确认托管依赖配置完整性
    检查host.json的managedDependency配置是否符合标准结构,避免拼写或格式错误:

    {
        "version": "2.0",
        "managedDependency": {
            "enabled": true
        }
    }
    
  • 强制触发依赖同步
    托管依赖有时不会自动更新,可通过以下方式强制同步:

    1. 进入Azure门户的函数应用,打开配置 > 应用程序设置
    2. 添加或更新FUNCTIONS_POWERSHELL_MANAGED_DEPENDENCIES_AUTOUPDATE设置,值设为true
    3. 重启函数应用;本地开发的话,删除项目根目录的.powershell文件夹后重新启动项目,让系统重新下载模块。
  • 调整模块版本兼容性
    Microsoft.Graph.Authentication 2.x和Az.Accounts 2.5.4可能存在版本冲突,尝试调整版本:

    • 给Microsoft.Graph.Authentication指定具体兼容版本,比如2.16.0
    • 或者将Az.Accounts升级到匹配版本,比如2.13.0
  • 临时手动导入模块
    如果托管依赖仍不生效,可在函数代码开头手动导入模块(注意:会增加启动时间,优先解决托管依赖问题):

    Import-Module Microsoft.Graph.Authentication -MinimumVersion 2.0
    
  • 验证模块部署状态
    登录函数应用的Kudu控制台,进入D:\home\data\ManagedDependencies\202x\xx\xx路径,确认Microsoft.Graph.Authentication文件夹存在且模块文件完整。

内容的提问来源于stack exchange,提问作者MattP

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 16:23:17