导入Microsoft.Graph.Users.Actions模块时遇Azure.Core依赖及命令未识别问题
Microsoft Graph.Users.Actions模块导入与命令调用问题解决
问题背景
原本使用Import-Module Microsoft.Graph.Mail模块正常运行,为使用Invoke-MgForwardUserMessage cmdlet,改用Microsoft.Graph.Users.Actions模块。执行Install-Module Microsoft.Graph.Users.Actions -Scope AllUsers并确认安装后,遇到以下问题:
- 导入模块时报错:
Import-Module : Could not load file or assembly 'Azure.Core, Version=1.35.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' or one of its dependencies. The system cannot find the file specified.
- 尝试安装
Az模块、卸载AzureRm后,未关闭PowerShell ISE时导入模块出现警告:
WARNING: Selected Microsoft Graph profile 'v1.0' does not exist for module 'Microsoft.Graph.Users.Actions'. No cmdlets were loaded.
- 调用
Invoke-MgForwardUserMessage时提示命令未被识别。
解决步骤
1. 修复Azure.Core依赖缺失问题
- 卸载冲突的Azure相关模块:
Uninstall-Module -Name Az -AllVersions -Force Uninstall-Module -Name AzureRm -AllVersions -Force - 手动安装指定版本的Azure.Core模块:
Install-Module -Name Azure.Core -RequiredVersion 1.35.0 -Scope AllUsers -Force - 重启PowerShell ISE,确保环境加载新的依赖组件。
2. 切换兼容的Microsoft Graph Profile
Microsoft.Graph.Users.Actions的部分cmdlet仅支持beta版本的Graph API,执行以下命令切换配置:
Select-MgProfile -Name beta
之后重新导入模块:
Import-Module Microsoft.Graph.Users.Actions -Force
3. 清理模块版本冲突
- 检查已安装的Microsoft Graph模块版本:
Get-Module -ListAvailable Microsoft.Graph.* - 若存在多版本冲突,卸载所有旧版本的目标模块:
Uninstall-Module -Name Microsoft.Graph.Users.Actions -AllVersions -Force - 重新安装最新稳定版模块:
Install-Module -Name Microsoft.Graph.Users.Actions -Scope AllUsers -Force -AllowClobber
4. 验证命令可用性
导入模块后,执行以下命令确认Invoke-MgForwardUserMessage是否加载成功:
Get-Command Invoke-MgForwardUserMessage
原因说明
Microsoft.Graph.Mail是独立功能模块,依赖的Azure组件版本较低或内置了所需依赖,而Microsoft.Graph.Users.Actions需要指定版本的Azure.Core组件支持,因此出现依赖缺失报错。Microsoft.Graph.Users.Actions的部分cmdlet未在默认的v1.0 Graph API Profile中收录,必须切换到beta版本才能加载这些命令。
内容的提问来源于stack exchange,提问作者NealWalters
相关产品推荐
相关产品推荐

