Я пытаюсь получить информацию о MFA в моем приложении C #.Я уже достиг удовлетворительных результатов в Powershell, но я изо всех сил стараюсь сделать то же самое в C #.
Мой код в Powershell:
Get-MsolUser -SearchString c.test@mytenant.com |
Where-Object {$_.StrongAuthenticationRequirements -like “*”} |
Select-Object UserPrincipalName, DisplayName, @{n='MFA';e=
{$_.StrongAuthenticationRequirements.State}}, @{n='Methods'; e=
{($_.StrongAuthenticationMethods).MethodType}}, @{n='Default Method'; e=
{($_.StrongAuthenticationMethods).IsDefault}}
UserPrincipalName : c.test@mytenant.com
DisplayName : Cyril test
MFA : Enforced
Methods : {OneWaySMS, TwoWayVoiceMobile, PhoneAppOTP,
PhoneAppNotification}
Default Method : {False, False, False, True}
Как видите, я получаюСостояние MFA и используемые методы.
Теперь я хочу сделать то же самое в C #.
Моя функция:
public static List<string> GetMFA(Runspace runspace, string nom)
{
List<string> listResult = new List<string>();
try
{
Command getLicenseCommand = new Command("Get-MsolUser");
getLicenseCommand.Parameters.Add(new CommandParameter("SearchString", nom));
var pipe = runspace.CreatePipeline();
pipe.Commands.Add(getLicenseCommand);
var props = new string[] { "displayname", "userprincipalname", "StrongAuthenticationRequirements" };
Command CommandSelect = new Command("Select-Object");
CommandSelect.Parameters.Add("Property", props);
pipe.Commands.Add(CommandSelect);
// Execute command and generate results and errors (if any).
Collection<PSObject> results = pipe.Invoke();
if (results.Count != 0)
{
var error = pipe.Error.ReadToEnd();
if (error.Count > 0)
{
throw new Exception(error[0].ToString());
}
foreach (PSObject resultat in results)
{
string dn = resultat.Properties["displayname"].Value.ToString();
string upn = resultat.Properties["userprincipalname"].Value.ToString();
string mfa = resultat.Properties["StrongAuthenticationRequirements"].Value.ToString();
string res = dn + '/' + upn + '/' + mfa;
listResult.Add(res);
}
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return listResult;
}
Свойство "StrongAuthenticationRequirements" не возвращаетсячто-то вроде «Enforced», но
System.Collections.Generic.List`1[Microsoft.Online.Administration.StrongAuthenticationRequirement]
Что мне здесь не хватает?