PowerShellWhere-Object 查询括号之间的空或 NULL 内容

Lia*_*gan 0 powershell filtering

如果我的问题没有完全描述我在这里要问的内容,我很抱歉!我不确定如何过滤大括号/括号之间的字段内容或缺失。我的热门搜索结果返回这篇文章,我认为它不能解决我的问题。

我正在尝试从 MSOnline/AzureAD 中提取禁用/未设置多重身份验证选项的所有用户。这个事实有点微不足道,但它设定了背景......

我有以下查询,它返回一个我知道没有配置 StrongAuthenticationRequirements 值的测试用户。

> 获取-MsolUser -UserPrincipalName test@contoso.com | 选择 UserPrincipalName、DisplayName、StrongAuthenticationRequirements

UserPrincipalName DisplayName StrongAuthenticationRequirements
----------------- ---------------------- ---------------------- ----------
test@contoso.com 测试帐户 {}

我还可以使用Where-Object 运行查询来查找那些确实设置了值的对象。

> 获取-MsolUser | where-object { $_.StrongAuthenticationRequirements -like "*Mi​​crosoft.Online.Administration.StrongAuthenticationRequirement*" } | 选择 UserPrincipalName、DisplayName、StrongAuthenticationRequirements

UserPrincipalName DisplayName StrongAuthenticationRequirements
----------------- ---------------------- ---------------------- ----------
test@contoso.com 测试帐户 {Microsoft.Online.Administration.StrongAuthenticationRequirement}

我的问题是;如何运行非用户特定查询来查找 StrongAuthenticationRequirement 字段为“{}”的所有实例?

提前致谢!

Adm*_*ngs 5

由于StrongAuthenticationRequirements是一个集合,因此空集合Count的值为0

Get-MsolUser -All | Where-Object { $_.StrongAuthenticationRequirements.Count -eq 0 } |
    Select UserPrincipalName,DisplayName,StrongAuthenticationRequirements
Run Code Online (Sandbox Code Playgroud)