powershell - 如何让 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。我会很感激任何帮助。谢谢你。
解决方案
据我所知,该属性永远不会相等$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
推荐阅读
- xml - 类型不匹配:scala.xml.NodeBuffer vs Seq[scala.xml.Node]
- python - 如何从熊猫数据框中的当前行中减去前一行以创建一个新列,以每个名称重新启动进程?
- python - 自定义 jupyter notebook 的打印版本
- c# - SendGrid 电子邮件 - RegisterConfirmation - 电子邮件未收到
- python - Python:将列中的行相乘并将其整合
- python - 如何使用带有 Python 的 selenium 库在帧之间切换?
- excel - 如果在 VBA 中找不到值,则显示消息框
- python - 我无法用 selenium 解析正确的 html 代码
- android - android ListAdapter 使用 MVVM 选择状态
- android - 如何减少 TabLayout 中的选项卡数量(每次都面临错误)