我能够导入AzureAD模块并能够使用Connect-AzureADPowerShell cmdlet连接 AzureAD C#。当我想列出用户时,我只是简单地使用Get-AzureADUser了所有用户。但是当我想使用 列出特定用户时Get-AzureADUser -SearchString 'user@domain.com',我无法列出。试过一个: Runspace runspace = RunspaceFactory.CreateRunspace(); runspace.Open(); Pipeline pipeline = runspace.CreatePipeline(); pipeline.Commands.AddScript("Import-Module AzureAD"); //importing //passing credentials pipeline.Commands.AddScript("$Username = '"+uname+"'"); pipeline.Commands.AddScript("$Password = ConvertTo-SecureString '"+pwd+"'-AsPlainText -Force"); pipeline.Commands.AddScript("$LiveCred = New-Object System.Management.Automation.PSCredential $Username, $Password"); pipeline.Commands.AddScript("Connect-AzureAD -Credential $LiveCred"); pipeline.Commands.AddScript("Get-AzureADUser -SearchString 'user@domain.com'");//needed one foreach(PSObject info in pipeline.Invoke()) { Console.WriteLine(info.Members["DisplayName"].Value);//not working }实际的PowerShellcmdlet:PS C:\Windows\system32> Get-AzureADUser -SearchString 'user@domain.com'ObjectId DisplayName UserPrincipalName UserType-------- ----------- ----------------- --------c36eb0fa-2500-4b3f-9499-1852e9ae44fc username user@domain.com Member在列出所有用户的情况下,我的c#代码工作正常。但是对于特定用户,我的c#代码不起作用。我哪里做错了?用于列出所有用户:// 工作正常 pipeline.Commands.AddScript("Get-AzureADUser"); var result = pipeline.Invoke(); for(int i=0;i<result.Count;i++) { Console.Write(result[i].Members["DisplayName"].Value); }
1 回答
- 1 回答
- 0 关注
- 251 浏览
添加回答
举报
0/150
提交
取消