gpt4 book ai didi

c# - 术语 'Connect-AzureAD' 未被识别为 cmdlet 的名称

转载 作者:太空宇宙 更新时间:2023-11-03 14:41:39 28 4
gpt4 key购买 nike

从 Azure AD 中的 C# 应用程序运行 powershell 脚本。

添加到 DLL 引用下方

  • 系统.管理.自动化
  • Microsoft.Online.Administration.Automation.PSModule.Resources
  • Microsoft.Online.Administration.Automation.PSModule

Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript("Import-Module AzureAD -Force;");
pipeline.Commands.AddScript("$password = ConvertTo-SecureString " + "\"abc1234\"" + " -AsPlainText -Force");
pipeline.Commands.AddScript("$Cred = New-Object System.Management.Automation.PSCredential (" + "\"abc@abc.com\"" + ", $password)");
pipeline.Commands.AddScript("Connect-AzureAD -Credential $Cred");
pipeline.Commands.AddScript("Get-AzureADApplication -Filter " + "\"DisplayName eq " + "\'PortalTestApp\'" + "\"");
var result = pipeline.Invoke();

获取错误:

The term 'Connect-AzureAD' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

最佳答案

我在使用 PowerShell v7 时遇到问题,与 PS v5 不同,您必须在安装后使用 Import-Module AzureAD 导入模块。该错误与从 PSGallery 等模块源安装后未导入它相同。

关于c# - 术语 'Connect-AzureAD' 未被识别为 cmdlet 的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56543597/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com