【发布时间】:2018-01-22 08:00:27
【问题描述】:
我需要从 C# 执行这个 PowerShell 脚本。我想为单个用户禁用 MFA。
我尚未安装 Azure PowerShell。那么要执行下面的脚本,需要什么先决条件呢?
我无法在我的系统中找到此 .dll:
Microsoft.Online.Administration.StrongAuthenticationRequirement.dll
我的代码:
string script = "$auth = New-Object -TypeName Microsoft.Online.Administration.StrongAuthenticationRequirement " +
"$auth.RelyingParty = '*' " +
"$auth.State = 'Enforced' " +
"$auth.RememberDevicesNotIssuedBefore = 'Tuesday, November 28, 2017 10:26:43 AM' " +
//"$upn ="+txtUserName.Text+" "+jplanet@kellyservices.com
"$upn =abcd@abcd.com " +
"Set-MsolUser -UserPrincipalName $upn -StrongAuthenticationRequirements $auth ";
using (Runspace runspace = RunspaceFactory.CreateRunspace())
{
runspace.Open();
PowerShell ps = PowerShell.Create();
ps.Runspace = runspace;
ps.AddScript(scriptText);
ps.Invoke();
foreach (PSObject result in ps.Invoke())
{
Console.WriteLine(result);
}
return "";
}
【问题讨论】:
标签: powershell office365 azure-powershell