Microsoft Graph PowerShell -获取所有用户的MFA电话号码

qmelpv7a  于 2023-04-21  发布在  Shell
关注(0)|答案(1)|浏览(123)

我试图写一个脚本,将获得所有用户的MFA电话号码使用图模块。我能够得到的电话号码显示,但我很好奇,我如何才能得到UPN从MGUser在输出?

Install-Module Microsoft.Graph.Identity.Signins
Connect-Graph -Scopes UserAuthenticationMethod.ReadWrite.All
Select-MgProfile -Name v1.0

$mgUsers = Get-MgUser -All:$true | Select UserPrincipalName

foreach ($user in $mgUsers) {
    Get-MgUserAuthenticationPhoneMethod -UserId $user.UserPrincipalName | Select ID,PhoneNumber,PhoneType
    }

任何建议都非常感谢。谢谢

bweufnob

bweufnob1#

看起来你可以使用calculated property with Select-Object

Get-MgUser -All:$true -PipelineVariable user | ForEach-Object {
    Get-MgUserAuthenticationPhoneMethod -UserId $user.UserPrincipalName |
        Select-Object @{ N='UserPrincipalName'; E={ $user.UserPrincipalName }}, ID, PhoneNumber, PhoneType
}

相关问题