首页 > 解决方案 > 如何让 powershell 返回关闭 MFA 的所有用户?

问题描述

我对 powershell 脚本相当陌生,并且似乎在让 powershell 返回特定组中已关闭 MFA 的所有用户的列表时遇到问题。我计划稍后将输出放入 .csv 文件中。这是我到目前为止拼凑起来的:

Connect-MsolService


$GroupA = <Group ID>
$Path = <File Path>

Get-MsolGroupMember -GroupObjectId $GroupA | Get-MsolUser | ? 
{$_.StrongAuthenticationMethods -ne $null} | Sort DisplayName

但是,它返回的列表中的一些用户已打开 MFA。我会很感激任何帮助。谢谢你。

标签: powershellazure-active-directory

解决方案


据我所知,该属性永远不会相等$null,即使它是空的。例如。如果你运行:

Get-MsolUser | ForEach-Object { $_.StrongAuthenticationMethods.GetType() }

你会看到像这样的输出

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     List`1                                   System.Object
True     True     List`1                                   System.Object
True     True     List`1                                   System.Object

不管属性中是否有值,那里总是有一个列表对象。

我会接受@Theo 的建议,所以是这样的:

Connect-MsolService
$GroupA = <Group ID>
$Path = <File Path>
Get-MsolGroupMember -GroupObjectId $GroupA | Get-MsolUser | 
    Where-Object { $_.StrongAuthenticationMethods.Count -eq 0 } |
        Sort-Object DisplayName

推荐阅读