C# 无法在C中导入AzureAD模块#
以前有人遇到过这个问题吗?我计划使用C#调用AzureAD cmdlet。但是我尝试了很多方法来导入模块,比如:C# 无法在C中导入AzureAD模块#,c#,powershell,azure,azure-active-directory,C#,Powershell,Azure,Azure Active Directory,以前有人遇到过这个问题吗?我计划使用C#调用AzureAD cmdlet。但是我尝试了很多方法来导入模块,比如: InitialSessionState initialState = InitialSessionState.CreateDefault(); initialState.ExecutionPolicy = Microsoft.PowerShell.ExecutionPolicy.Bypass; initialState.AuthorizationManager = new Syste
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);
或
或
没有人可以导入模块。甚至我也使用完整路径“C:\Program Files\WindowsPowerShell\Modules\AzureAD\2.0.0.131\AzureAD.psd1”。我已经使用cmdlet“Install Module AzureAD-Force”在我的服务器中安装了AzureAD模块。在C#中调用导入模块时没有错误,但在尝试使用AzureAD cmdlet(如“Connect-AzureAD”)时,我将收到错误消息:
在模块“AzureAD”中找到“Connect AzureAD”命令,但无法加载该模块
我试过2个System.Management.Automation.dll,问题是一样的。我试过powershell 4.0,5.0。
有人有什么想法吗?非常感谢
顺便说一下,第一版Azure广告模块MSOnline运行良好
我在导入模块AzureAD cmdlet中启用了-Verbose日志,然后检查了PowerShell.Streams.Verbose中的详细输出,发现只有一条记录:
正在从路径“C:\Program Files(x86)\WindowsPowerShell\Modules\AzureAD\2.0.0.131\AzureAD.psd1”加载模块
但它应该有几十个详细输出,就像在powershell命令提示符中一样:
谢谢
-贾斯汀我也可以在我这边重做。我通过取消选中首选32位平台目标解决了此问题,更多详细信息请参阅屏幕截图 当我安装AzureADPreview模块时,我用于测试的C代码:
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript("Import-Module AzureADPreview -Force;");
pipeline.Commands.AddScript("Connect-AzureAD");
var result = pipeline.Invoke();
回答得很好。事实上,我只是自己解决了这个问题,但是是的,很好。我通过使用Powershell.Streams.Error log找到了这一点。谢谢
pipeline.Commands.AddScript("Import-Module");
pipeline.Commands[0].Parameters.Add("Name", "AzureAD");
var modules = pipeline.Invoke()
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript("Import-Module AzureADPreview -Force;");
pipeline.Commands.AddScript("Connect-AzureAD");
var result = pipeline.Invoke();