繁体   English   中英

通过 Powershell 为 AzureAD 设置 StrongAuthenticationUserDetails 电话号码?

[英]Setting StrongAuthenticationUserDetails PhoneNumber for AzureAD via Powershell?

这个标题真的很流畅。

在设置用于 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 不变,同时只更新电话号码。

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

Azure 反馈中甚至有针对该问题的已开票。

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

作为变通,你可以使用PowerShell的Watir的.NET华廷华廷记录通过Internet Explorer,以使自动化它。 因为我没有测试 Azure; 我无法为您创建可行的代码。

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

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

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

// 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 对象,我想出了以下脚本,它每 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)
}

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


我正在使用以下 Greasemonkey 脚本来更新备用电子邮件和电话( 现在可以通过 Graph API 更新电话,因此该脚本仅对电子邮件有用):

// ==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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM