具有Where子句的PowerShell选择对象子对象

时间:2018-10-18 19:31:25

标签: powershell

很抱歉,我的名字不好,我真的无法完全围绕我的要求

如果我运行此命令:

Get-MsolUser -UserPrincipalName bob.bobbington@bob.com |
    select UserPrincipalName, {$_.StrongAuthenticationMethods.MethodType},
           {$_.StrongAuthenticationMethods.IsDefault}

我回来了:

bob.bobbington@bob.com
{PhoneAppOTP, PhoneAppNotification, OneWaySMS, TwoWayVoiceMobile}
{False, True, False, False}

有什么办法可以使我从StrongAuthenticationMethods子对象中返回True方法类型吗?

所以这样的回报:

bob.bobbington@bob.com
PhoneAppNotification

如果可以单次返回所需的数据,我试图避免运行冗长的运行时脚本来遍历每个用户。

1 个答案:

答案 0 :(得分:2)

使用计算出的属性:

Get-MsolUser -UserPrincipalName 'bob.bobbington@bob.com' |
    Select-Object UserPrincipalName, @{n='AuthenticationMethod';e={
        $_.StrongAuthenticationMethods |
            Where-Object { $_.IsDefault } |
            Select-Object -Expand MethodType
    }}