通过Powershell为AzureAD设置强身份验证用户详细信息电话号码?



这个标题真的很流畅。

在设置计算机以与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                               :

但是,似乎没有类似的选项来设置强身份验证用户详细信息。

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

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

在 Azure 反馈中甚至有打开的票证。

有一个计划来做,但没有预计到达时间。我的猜测是,如果您只想使用Powershell,则必须等待。

作为解决方法,您可以使用powershell&watir for .NET或 Watin with Watin recorder 通过 Internet Explorer 实现自动化。 因为我没有测试的 Azure;我无法为您创建可行的代码。

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

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

接下来,单击记录按钮,然后单击所需的 HTML 元素 自动化。然后停止 WatIN 记录器并单击复制代码到 剪贴板图标。这将生成一些只需要 翻译成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对象探索,我想出了以下几点 脚本,每 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 脚本来更新备用电子邮件和电话(电话现在可以通过图形 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(

相关内容

最新更新