I’m trying to find a way in Powershell to export a list of MFA phone numbers for users. It appears that Graph can do this, but I’ve not found success.
Per the above article, I tried to use the following commands:
Get-MgUser -All:$true -PipelineVariable user | ForEach-Object {
Get-MgUserAuthenticationPhoneMethod -UserId $user.UserPrincipalName |
Select-Object @{ N='UserPrincipalName'; E={ $user.UserPrincipalName }}, ID, PhoneNumber, PhoneType
}
Executing this results in “ForEach-Object : Cannot bind argument to parameter ‘UserId’ because it is an empty string.”
I tried the OP’s original commands:
$mgUsers = Get-MgUser -All:$true | Select UserPrincipalName
foreach ($user in $mgUsers) {
Get-MgUserAuthenticationPhoneMethod -UserId $user.UserPrincipalName | Select ID,PhoneNumber,PhoneType
}
This did start outputting phone numbers, but no names. There’s an Id column, but all of the IDs are the same, so I still have no means of identifying who is who.
I tried the solution in one of the replies (that the OP indicated worked for them), but this also did not provide output. Instead of an error it showed only the Id and UPN data, but the UPN was the same for all of the IDs.
I’m at a loss. I’ve never used Graph before, and am trying to use this data to true-up some of the data in one of our on-premise databases. If I can get a list of these phone numbers it’ll be a lot easier than going through hundreds of users manually in Azure to visually compare their MFA number to the number on record. :/
jestergi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.