【问题标题】:How to execute multi factor auth from powershell如何从 powershell 执行多因素身份验证
【发布时间】: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


    【解决方案1】:

    1.先决条件:

    下载并安装以下模块。

    首先从 Microsoft 下载中心安装 Microsoft Online Services Sign-In Assistant for IT Professionals RTW

    然后安装Azure Active Directory Module for Windows PowerShell (64-bit version),点击运行运行安装包。

    1. 打开 Windows PowerShell
    2. 运行以下命令

      Get-ExecutionPolicy

      如果输出不是 “无限制”,运行以下命令。

      Set-ExecutionPolicy Unrestricted –Scope CurrentUser

      确认设置更改。

    3. 通过 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 
    

    【讨论】:

      猜你喜欢
      • 2020-05-16
      • 2013-08-31
      • 1970-01-01
      • 2021-11-06
      • 2017-12-16
      • 2014-08-31
      • 2018-07-30
      • 2022-07-25
      • 2018-07-12
      相关资源
      最近更新 更多