小编Jus*_*Shi的帖子

无法在C#中导入AzureAD模块

有人遇到过这个问题吗?我计划使用C#调用AzureAD cmdlet。但是我尝试了多种导入模块的方法,例如:

InitialSessionState initialState = InitialSessionState.CreateDefault();
initialState.ExecutionPolicy = Microsoft.PowerShell.ExecutionPolicy.Bypass;
initialState.AuthorizationManager = new System.Management.Automation.AuthorizationManager("O365");
initialState.LanguageMode = System.Management.Automation.PSLanguageMode.FullLanguage;
initialState.ImportPSModule(new string[] {"AzureAD" });
Runspace runspace = RunspaceFactory.CreateRunspace(initialState);
Run Code Online (Sandbox Code Playgroud)

要么

pipeline.Commands.AddScript("Import-Module -Name AzureAD -Force; Get-Module");
var modules = pipeline.Invoke();
Run Code Online (Sandbox Code Playgroud)

要么

pipeline.Commands.AddScript("Import-Module");
pipeline.Commands[0].Parameters.Add("Name", "AzureAD");
var modules = pipeline.Invoke()
Run Code Online (Sandbox Code Playgroud)

没有人可以导入该模块。即使我使用完整路径“ C:\ Program Files \ WindowsPowerShell \ Modules \ AzureAD \ 2.0.0.131 \ AzureAD.psd1”。我已使用cmdlet“ Install-Module AzureAD -Force”在服务器中安装AzureAD模块。当我在C#中调用import-module时没有错误,但是当我尝试使用AzureConnect cmdlet(如“ Connect-AzureAD”)时,我将收到错误消息:

在模块“ AzureAD”中找到“ Connect-AzureAD”命令,但无法加载该模块。

我已经尝试了两个System.Management.Automation.dll,问题是相同的。我尝试了Powershell 4.0、5.0。 在此处输入图片说明

有人有什么想法吗?非常感谢。

顺便说一句,第一个版本的Azure AD模块MSOnline正常运行。

我在导入模块AzureAD cmdlet中启用了-Verbose日志,然后在PowerShell.Streams.Verbose中检查了VERBOSE输出,发现只有一条记录:

从路径'C:\ Program Files(x86)\ WindowsPowerShell \ Modules \ AzureAD \ …

c# powershell azure azure-active-directory

3
推荐指数
1
解决办法
906
查看次数

标签 统计

azure ×1

azure-active-directory ×1

c# ×1

powershell ×1