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

Azure Function调用AzureAD模块报错:架构不匹配及命令未识别

解决方案

1. 解决架构不匹配问题

  • 登录Azure门户,定位到目标函数应用
  • 进入配置 > 常规设置
  • 将平台架构从X86切换为64位
  • 保存设置后重启函数应用

2. 解决Get-AzureADUser未识别及模块兼容问题

方案A:修复AzureAD模块使用(不推荐,模块已弃用)

AzureAD模块仅兼容64位架构,且其登录逻辑与Az模块独立,需调整脚本:

using namespace System.Net

param($Request, $TriggerMetadata)

# 导入AzureAD模块(需64位架构支持)
Import-Module AzureAD -UseWindowsPowerShell
# 用托管身份连接AzureAD,而非Az模块的登录命令
Connect-AzureAD -Identity
# 获取所有AAD用户
$allUsers = Get-AzureADUser -All $True

Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    StatusCode = [HttpStatusCode]::OK
    Body = $allUsers
})

注意:AzureAD模块已被微软弃用,仅通过Windows PowerShell兼容层在PowerShell 7中运行,存在稳定性风险。

方案B:改用Microsoft Graph PowerShell模块(推荐)

Microsoft Graph模块原生支持PowerShell 7,是AzureAD模块的官方替代方案,步骤如下:

  1. 更新requirements.psd1配置文件:
@{
    'Az.Accounts' = '2.5.4'
    'Microsoft.Graph.Users' = '2.*'
}
  1. 修改run.ps1脚本:
using namespace System.Net

param($Request, $TriggerMetadata)

# 导入Microsoft Graph用户模块
Import-Module Microsoft.Graph.Users
# 用托管身份连接Graph,指定所需权限
Connect-MgGraph -Identity -Scopes "User.Read.All"
# 获取所有AAD用户
$allUsers = Get-MgUser -All

Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    StatusCode = [HttpStatusCode]::OK
    Body = $allUsers
})
  1. 给托管身份授予Microsoft Graph API的User.Read.All应用权限(需管理员同意权限)

额外注意事项

  • 切换架构后需等待函数应用完全重启再测试
  • 使用Microsoft Graph时,必须配置应用权限而非委派权限

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 10:09:55