我需要从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 "";
}
答案 0 :(得分:0)
<强> 1。先决条件:
下载并安装以下模块。
首先从Microsoft下载中心安装Microsoft Online Services Sign-In Assistant for IT Professionals RTW。
然后安装Azure Active Directory Module for Windows PowerShell (64-bit version),然后单击“运行”以运行安装程序包。
运行以下命令
Get-ExecutionPolicy
如果输出不是 &#34;不受限制&#34;,运行以下命令。
Set-ExecutionPolicy Unrestricted –Scope CurrentUser
确认更改设置。
通过PowerShell连接到MsolService 运行以下命令将弹出一个弹出窗口,要求您输入Office 365管理员凭据。
$UserCredential = Get-Credential
Import-Module MSOnline
Connect-MsolService –Credential $UserCredential
启用强>
$St = New-Object -TypeName Microsoft.Online.Administration.StrongAuthenticationRequirement
$St.RelyingParty = "*"
$Sta = @($St)
Set-MsolUser -UserPrincipalName ifarr@contoso.com -StrongAuthenticationRequirements $Sta
停用强>
$Sta = @()
Set-MsolUser -UserPrincipalName ifarr@contoso.com -StrongAuthenticationRequirements $Sta