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

导入Microsoft.Graph.Applications后,Get-MgUser/New-MgUser命令无法识别如何解决?

问题:运行New-MgUser或Get-MgUser时提示命令未识别

已执行Import-Module Microsoft.Graph.Applications命令,并使用多个作用域运行Connect-MgGraph完成连接,但运行New-MgUser时收到以下错误:

Get-MgUser: The term 'Get-MgUser' 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.

解决方法

  • 导入正确的模块:New-MgUser和Get-MgUser属于Microsoft.Graph.Users模块,而非Microsoft.Graph.Applications。执行以下命令导入模块:

    Import-Module Microsoft.Graph.Users
    

    若需要使用多个Graph模块,也可一次性导入完整模块(按需选择):

    Import-Module Microsoft.Graph -Force
    
  • 确认模块已安装:如果未安装Microsoft.Graph.Users模块,先执行安装命令(根据权限选择作用域):

    # 当前用户安装
    Install-Module Microsoft.Graph.Users -Scope CurrentUser
    # 所有用户安装(需管理员权限)
    Install-Module Microsoft.Graph.Users -Scope AllUsers
    

    可先执行Get-Module -ListAvailable Microsoft.Graph.Users检查模块是否已存在。

  • 更新到最新模块版本:旧版本模块可能存在命令缺失,执行更新命令:

    Update-Module Microsoft.Graph.Users
    
  • 验证连接作用域:确保Connect-MgGraph时包含用户操作所需的权限作用域,例如:

    Connect-MgGraph -Scopes "User.ReadWrite.All", "Directory.ReadWrite.All"
    

    (注:权限不足会导致命令执行失败,但不会触发“命令未识别”错误,此步骤为后续操作提前验证)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 03:12:33