首页 > 其他分享 >Microsoft 365 开发:如何通过脚本批量获取用户MFA状态以及Default MethodType

Microsoft 365 开发:如何通过脚本批量获取用户MFA状态以及Default MethodType

时间:2022-12-11 14:32:39浏览次数:67  
标签:MFA Get Default UserPrincipalName _. DefaultMethodType User MethodType

Blog链接:​​​https://blog.51cto.com/13969817​

今天给大家分享一下如何通过脚本检验用户是否启用了MFA以及DefaultMethodType,首先我们确保环境:

·       部署了MSOnline的Powershell Module

·       执行脚本的用户有Global Administrator Role

具体操作方法如下所示:

1.      通过命令:Connect-MsolService, 连接MsolService,如下所示:

Microsoft 365 开发:如何通过脚本批量获取用户MFA状态以及Default MethodType_Default Method type

2.      通过命令 Install-module msonline,安装msonline 的powershell module,如下所示:

Microsoft 365 开发:如何通过脚本批量获取用户MFA状态以及Default MethodType_MFA 状态_02

3.      获取用户MFA的脚本,如下所示:

Function Get-PerUserMFAStatus {
[CmdletBinding(DefaultParameterSetName='All')]
param(
[Parameter(
Mandatory = $false,
ParameterSetName = 'UPN',
Position = 0
)]
[string[]] $UserPrincipalName,
[Parameter(
Mandatory = $false,
ParameterSetName = 'All'
)]
[switch] $All
)

BEGIN {
if (-not (Get-MsolDomain -ErrorAction SilentlyContinue)) {
Write-Error "You must connect to the MSolService to continue" -ErrorAction Stop
}
}
PROCESS {
if ($PSBoundParameters.ContainsKey('UserPrincipalName')) {
$MsolUserList = foreach ($MsolUser in $UserPrincipalName) {
try {
Get-MsolUser -UserPrincipalName $MsolUser -ErrorAction Stop
} catch {
Write-Error $_.Exception.Message
}
}
} else {
$MsolUserList = Get-MsolUser -All -ErrorAction Stop | Where-Object {$_.UserType -ne 'Guest' -and $_.DisplayName -notmatch 'On-Premises Directory Synchronization'}
}
foreach ($User in $MsolUserList) {
if ($User.StrongAuthenticationRequirements) {
$PerUserMFAState = $User.StrongAuthenticationRequirements.State

} else {
$PerUserMFAState = 'Disabled'
}

$MethodType = $User.StrongAuthenticationMethods | Where-Object {$_.IsDefault -eq $true} | select -ExpandProperty MethodType

if ($MethodType) {
switch ($MethodType) {
'OneWaySMS' {$DefaultMethodType = 'SMS Text Message' }
'TwoWayVoiceMobile' {$DefaultMethodType = 'Call to Phone' }
'PhoneAppOTP' {$DefaultMethodType = 'TOTP' }
'PhoneAppNotification' {$DefaultMethodType = 'Authenticator App' }
}
} else {
$DefaultMethodType = 'Not Enabled'
}

[PSCustomObject]@{
UserPrincipalName = $User.UserPrincipalName
DisplayName = $User.DisplayName
PerUserMFAState = $PerUserMFAState
DefaultMethodType = $DefaultMethodType

}

$MethodType = $null
}

}

END {}
}

Microsoft 365 开发:如何通过脚本批量获取用户MFA状态以及Default MethodType_MFA 状态_03

4.    获取账户的MFA状态以及Default Method Type,如下所示:

C:\> Get-PerUserMFAStatus -UserPrincipalName User1, User2

Microsoft 365 开发:如何通过脚本批量获取用户MFA状态以及Default MethodType_MFA 状态_04

若要获取全部用户的状态,那么输入命令:​​Get-PerUserMFAStatus​​ -All即可

整理本文,希望给日后有需要的小伙伴提供帮忙,谢谢大家阅读

标签:MFA,Get,Default,UserPrincipalName,_.,DefaultMethodType,User,MethodType
From: https://blog.51cto.com/u_13969817/5928311

相关文章