Blog链接:https://blog.51cto.com/13969817
今天给大家分享一下如何通过脚本检验用户是否启用了MFA以及DefaultMethodType,首先我们确保环境:
· 部署了MSOnline的Powershell Module
· 执行脚本的用户有Global Administrator Role
具体操作方法如下所示:
1. 通过命令:Connect-MsolService, 连接MsolService,如下所示:
2. 通过命令 Install-module msonline,安装msonline 的powershell module,如下所示:
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 {}
}
4. 获取账户的MFA状态以及Default Method Type,如下所示:
C:\> Get-PerUserMFAStatus -UserPrincipalName User1, User2
若要获取全部用户的状态,那么输入命令:Get-PerUserMFAStatus
-All即可
整理本文,希望给日后有需要的小伙伴提供帮忙,谢谢大家阅读
标签:MFA,Get,Default,UserPrincipalName,_.,DefaultMethodType,User,MethodType From: https://blog.51cto.com/u_13969817/5928311