Jus*_*Shi 3 c# powershell azure azure-active-directory
有人遇到过这个问题吗?我计划使用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 \ 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();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
906 次 |
最近记录: |