用于获取 MFA 状态的 PowerShell 脚本

问题描述 投票:0回答:1

我们使用 Microsoft 365 并正在实施 MFA。我正在寻找一种方法来提取显示每个用户状态的报告。看来这只能通过 PowerShell 来完成。但我发现的脚本要么只给出两种状态,“启用”和“禁用”,要么给出不正确的状态。

下面的脚本错误地为禁用了 MFA 的用户提供“已启用”状态。你知道如何纠正吗?

Get-MsolUser -All | Select-Object DisplayName, UserPrincipalName, @{
    Name = 'MFA Status'; 
    Expression = {
        if ($_.StrongAuthenticationRequirements.State -eq "Enforced") {
            "Enforced"
        } elseif ($_.StrongAuthenticationMethods -ne $null) {
            "Enabled"
        } else {
            "Disabled"
        }
    }
} | Export-Csv "D:\MFAStatus.csv" -NoTypeInformation

我尝试了不同的脚本和方法,但没有成功,希望能更正此脚本。

powershell
1个回答
0
投票

您必须以不同的方式访问方法,尝试像这样更改脚本:

Get-MsolUser -All | Select-Object DisplayName, UserPrincipalName, @{
    Name = 'MFA Status';
    Expression = {
        if ($_.StrongAuthenticationRequirements.Count -gt 0) {
            "Enforced"
        } elseif ($_.StrongAuthenticationMethods.Count -gt 0) {
            "Enabled"
        } else {
            "Disabled"
        }
    }
} | Export-Csv "D:\MFAStatus.csv" -NoTypeInformation
© www.soinside.com 2019 - 2024. All rights reserved.