Payton Flint's Tech Blog
Menu
  • Home
  • Blog
  • Categories
  • Resources
  • About
  • Contact
Menu

Azure – Get Group MFA Registration Info

Posted on November 8, 2024November 8, 2024 by paytonflint

If you’ve deployed multifactor authentication (MFA) at an enterprise scale, you’ll know it can be fraught with challenges. You may need to deploy to individual departments, or perhaps take a phased approach and deploy in traches. However you end up deciding to do your MFA rollout, you will likely need to specify a target group, and you’ll want to retrieve registration percentage information for this group.

I found this to be quite a lot easier with the old Azure PowerShell modules than the new Microsoft Graph one. But, then I had to use two modules to do so. And, I am expecting that those will become deprecated sooner than later. Graph is Microsoft’s clear path forward, so I have opted to use it instead.

Here is the PowerShell script I put together that uses Microsoft’s Graph Beta Endpoint features to build a hashtable of userPrincipalNames and a corresponding boolean value for whether they had the “microsoftAuthenticator” authentication method specified. From this, I then derive the MFA registration percentage. I have intentionally written this so that the output it is very flexible, and, being a hashtable, performance-minded. For instance, it would be very fast and easy to call upon the hashtable to send an email to all users within your target group that have not yet registered for MFA. I am not thrilled with the query performance; because of the repeated calls to the Graph API, it is slower than I would like. It seems Microsoft must have some fairly restrictive rate limits in place. There is the possibility of chunking users and doing fewer API calls, but I did not work that out.

Here is the link to the script on my GitHub:

https://github.com/p8nflnt/Cloud-Toolbox/blob/main/azure/Get-AzGroupAuthMethodsHT.ps1

And here is the script:

<#
.SYNOPSIS
    Use the Microsoft Graph beta endpoint to generate a hashtable of
    userPrincipalNames within a group and a corresponding boolean value for 
    whether they have the "microsoftAuthenticator" auth method specified.

.NOTES
    Name: Get-AzGroupAuthMethodHT
    Author: Payton Flint
    Version: 1.0
    DateCreated: 2024-Nov

.LINK
    https://github.com/p8nflnt/Cloud-Toolbox/blob/main/azure/Get-AzGroupAuthMethodsHT.ps1
    
Azure – Get Group MFA Registration Info
#> function Get-AzGroupAuthMethodsHT { param ( [string]$GroupName ) # connect to microsoft graph with required scopes Connect-MgGraph -Scopes "Group.Read.All", "User.Read.All" -ErrorAction Stop # get group ID by name $group = Get-MgGroup -Filter "displayName eq '$GroupName'" if (-not $group) { Write-Output "Group '$GroupName' not found." return $null } # get all group members $groupMembers = Get-MgGroupMember -GroupId $Group.Id -All # initialization for loop $userDetails = @{} $i = 0 foreach ($user in $groupMembers) { # define uri for the beta endpoint $uri = "https://graph.microsoft.com/beta/users/$($user.Id)/authentication/methods" # increment count $i++ try { # get user auth methods via beta endpoint $authUser = Invoke-MgGraphRequest -Uri $uri -Method GET # print status to console Write-Host "$i of $($groupMembers.count) - Retrieved authentication methods - $($user.AdditionalProperties['userPrincipalName'])" # detect if "microsoftAuthenticator" is in the authentication methods $authMethod = $authUser.Values.Values -contains "microsoftAuthenticator" # add upn as key & bool authMethod to hashtable $userDetails[$user.AdditionalProperties["userPrincipalName"]] = $authMethod } catch { Write-Host "Failed to retrieve authentication methods for user $($user.Id)" } } # return hashtable return $userDetails } # specify group name and invoke function $groupName = "<GROUP NAME>" $groupAuthHT = Get-AzGroupAuthMethodsHT -GroupName $groupName # calculate percentage from hashtable if ($groupAuthHT) { $mfaUsersCount = ($groupAuthHT.Values | Where-Object { $_ -eq $True }).Count $percentage = "{0:N2}" -f (($mfaUsersCount / $groupAuthHT.Keys.Count) * 100) + '%' Write-Host "$mfaUsersCount out of $($groupAuthHT.Keys.Count), or $percentage of users in $groupName have an authentication method specified." }

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

About The Author

Author's Portrait

In my journey as a technologist and 11 years of experience as an IT professional, I have found my niche as Director of Infrastructure Services; developing my skillsets in management, scripting, cloud infrastructure, identity management, and networking.

I have experience as a Systems Administrator and Engineer for large enterprises including the DoD, government agencies, and a nuclear-generation site.

I've been blessed to collaborate with engineers at esteemed Fortune 50 corporations, and one of Africa's largest, to ensure successful implementation of my work.

GitHub Button

Credentials

M365 Endpoint Administrator Associate
M365 Fundamentals
Microsoft AZ-900
CompTIA CSIS
CompTIA CIOS
CompTIA Security+
CompTIA Network+
CompTIA A+
  • April 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
© 2022 Payton Flint | The views and opinions expressed on this website belong solely to the author/owner and do not represent the perspectives of any individuals, institutions, or organizations, whether affiliated personally or professionally, unless explicitly stated otherwise. The content and products on this website are provided as-is with no warranties or guaranties, are for informational/demonstrative purposes only, do not constitute professional advice, and are not to be used maliciously. The author/owner is not responsible for any consequences arising from actions taken based on information provided on this website, nor from the use/misuse of products from this site. All trademarks are the property of their respective owners.