【问题标题】:Setting StrongAuthenticationUserDetails PhoneNumber for AzureAD via Powershell?通过 Powershell 为 AzureAD 设置 StrongAuthenticationUserDetails PhoneNumber?
【发布时间】:2020-08-02 02:17:56
【问题描述】:

这个标题真的很流畅。

在设置计算机以使用 Azure Active Directory 时,我们会让 IT 进行初始设置和配置。这包括首次登录和加入 Azure Active Directory。登录时,它会强制您选择验证方法。我们会轻松使用我们的桌面电话或手机。

现在是我们更新第二因素电话号码的时候了。我知道一种通过 Azure AD Web UI 手动执行此操作的方法,但我正在寻找一种脚本方式来在 PowerShell 中设置该数字。

这是我通过 PowerShell 检索号码的方法。

Get-msoluser -UserPrincipalName "email@emailaddress.com" | Select-Object -ExpandProperty StrongAuthenticationUserDetails

该代码返回此信息:

ExtensionData                     : System.Runtime.Serialization.ExtensionDataObject
AlternativePhoneNumber            :
Email                             :
OldPin                            :
PhoneNumber                       : +1 5554445555
Pin                               :

但是,设置 StrongAuthenticationUserDetails 似乎没有类似的选项。

我所有的搜索都发现了如何批量启用 2 因素身份验证,这不是我想要做的。我想保持 StrongAuthentication 不变,而只更新电话号码。

【问题讨论】:

  • 我在一周前遇到了同样的问题。 MSOL cmdlet 似乎缺乏执行此操作的方法。 AzureAD cmdlet 也是如此。
  • @bluuf 抱歉发帖。不应该读那么快。无论如何,看来powershell有只读访问权限。甚至还有开票 - feedback.azure.com/forums/169401-azure-active-directory/… 。有计划,但没有预计到达时间。对你来说不可能的答案是答案吗?
  • 我希望有任何方法可以以编程方式进行:/ 我不确定是否应该再等几天看看是否有任何解决方法。
  • @BožoStojković 你应该等几天。也许有人有某种解决方法。
  • @BožoStojković 我突然想到,您也许可以通过 powershell 创建一个 watir 自动化进程。看我的回答。

标签: powershell azure


【解决方案1】:

正如我在评论中所说,powershell 似乎有只读访问权限。

Azure feedback 上甚至还有开票。

有计划,但没有预计到达时间。我的猜测是,如果您只想使用 powershell,您将不得不等待。

作为解决方法,您可以使用 powershellwatir for .NETWatinWatin recorder 通过 Internet Explorer 将其自动化。因为我没有测试 Azure;我无法为您创建可行的代码。

使用 Watin 和 powershell - 你可以检查:https://cmille19.wordpress.com/2009/09/01/internet-explorer-automation-with-watin/

以下文字和代码,我想在这里备份一下,取自上述页面(所有致谢作者):

接下来单击记录按钮,然后单击您想要的 HTML 元素 自动化。然后停止 WatIN 记录器并单击复制代码到 剪贴板图标。这将产生一些只需要的 C# 代码 翻译成 PowerShell:

// Windows
WatiN.Core.IE window = new WatiN.Core.IE();

// Frames
Frame frame_sd_scoreboard = window.Frame(Find.ByName("sd") && Find.ByName("scoreboard"));

// Model
Element __imgBtn0_button = frame_sd_scoreboard.Element(Find.ByName("imgBtn0_button"));

// Code
__imgBtn0_button.Click();
window.Dispose();

所以,我现在知道了按钮的名称,并且它有 3 帧深。一个 小WatIN对象探索之后,我想出了follow 脚本,每 50 分钟点击一次按钮。

#Requires -version 2.0
#powershell.exe -STA

[Reflection.Assembly]::LoadFrom( "$ProfileDirLibrariesWatiN.Core.dll" ) | out-null
$ie = new-object WatiN.Core.IE("https://sd.acme.com/CAisd/pdmweb.exe")
$scoreboard  = $ie.frames | foreach {$_.frames } | where {$_.name –eq ‘sd’} |  foreach {$_.frames } | where {$_.name –eq ‘scoreboard’}
$button = $scoreboard.Element("imgBtn0_button")

while ($true)
{
    $button.Click()
    #Sleep for 50 minutes
    [System.Threading.Thread]::Sleep(3000000)
}

【讨论】:

  • 这与问题无关。您的命令设置了用户的电话号码,而不是 MFA 设置的电话号码。
  • 好吧,既然似乎没有其他解决方案,我会接受这个并给予赏金,除非有人给出更好的答案。现在,我想控制台中的一些 javascript 就足够了。
【解决方案2】:

免责声明:代码按原样提供。如果 MS 更改 Azure Portal 界面,它可能会停止工作。


我正在使用以下 Greasemonkey 脚本来更新备用电子邮件和电话(电话 can be updated via Graph API now,因此该脚本仅对电子邮件有用):

// ==UserScript==
// @name     Unnamed Script 548177
// @version  1
// @grant    none
// @namespace https://portal.azure.com
// ==/UserScript==

(function(){
document.addEventListener('keydown', function(e) {
  // press alt+shift+g
  if (e.keyCode == 71 && e.shiftKey && !e.ctrlKey && e.altKey && !e.metaKey) {
    const url = document.URL;
    const regex = /https:\/\/portal.azure.com\/#blade\/Microsoft_AAD_IAM\/UserDetailsMenuBlade\/UserAuthMethods\/userId\/[\w-]+\/adminUnitObjectId[\/]*\?\w+=(\d{9})&\w+=([\w\.-@]+)/;
    const params = url.match(regex);
    const allAuthRows = document.getElementsByClassName('ext-userauthenticationmethods-section-row');
    const authRowsArray = Array.from(allAuthRows);
    let emailRow;
    let phoneRow;
    let i;
    for (i =0; i < authRowsArray.length; i++) {
      if (authRowsArray[i].childNodes[1].childNodes[1].childNodes[0].data === 'Email') {
        emailRow = authRowsArray[i]
      }
      if (authRowsArray[i].childNodes[1].childNodes[1].childNodes.length > 1) {
        if (authRowsArray[i].childNodes[1].childNodes[1].childNodes[1].childNodes[0].data === 'Phone') {
          phoneRow = authRowsArray[i]
        }
      }
    }

    const emailInput = emailRow.childNodes[3].childNodes[1].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[2];
    const phoneInput = phoneRow.childNodes[3].childNodes[1].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[2];
    const event = new Event('input', {
        'bubbles': true,
        'cancelable': true
    });
    if (params[1] !== '000000000') {
      phoneInput.value = `+48 ${params[1]}`;
      phoneInput.dispatchEvent(event);
    }
    if (params[2] !== 'null') {
      emailInput.value = params[2];
      emailInput.dispatchEvent(event);
    }
    setTimeout(() => {
      const buttonArr = document.getElementsByClassName('azc-toolbarButton-container fxs-portal-hover');
      const saveButton = Array.from(buttonArr).find(e => e.title === 'Save');
      saveButton.click();
    } , 2000);    

  }
}, false);
})();

它要求你用这样的查询字符串打开 Azure 门户(我用 PowerShell 来做):

https://portal.azure.com/#blade/Microsoft_AAD_IAM/UserDetailsMenuBlade/UserAuthMethods/userId/$($u.ObjectId)/adminUnitObjectId/?param1=$newPhone&param2=$newMail

使用方法:

  • 一次只能打开一个标签页,否则您会收到Unable to sign-in 错误
  • 您有时会收到该错误消息,所以请稍等
  • 加载网站后按Alt+Shift+g触发脚本(可以在第一个if更改快捷方式)
  • 更新并保存数据后,按Ctrl+w 关闭当前选项卡,按Alt+Tab 切换到上一个窗口(应为PowerShell)
  • 您仍然可以使用代码更新手机。确保更改国家/地区代码(目前+48 用于波兰)

【讨论】:

    猜你喜欢
    • 2018-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-07
    • 1970-01-01
    • 1970-01-01
    • 2021-09-25
    • 2019-12-22
    相关资源
    最近更新 更多