I've been trying to report on multi-factor authentication (MFA) users lately, but our usual weekly script stopped working because MSOnline is deprecated. It just gives me a connection error about lacking the required privileges. I know the right way to do it now is through Microsoft Graph, but I'm struggling to find a working script. I've tried a few things, but I keep running into issues, like errors related to loading 'Microsoft.Graph.Authentication' or problems with 'Get-MgUserAuthenticationMethod' from different systems. I've even uninstalled and reinstalled the Microsoft Graph modules, but no luck. Does anyone have a script that's working for retrieving per-user MFA information?
5 Answers
I can't share my script since I'm traveling, but I think you might need to loop through your users with a foreach statement. First, grab the users using the user cmdlet, then get their authentication methods in the loop. Just remember, the result will return object IDs, so you'll need to replace those with method names using an if statement.
I had the same problem! I've reverted to using the Invoke-RestMethod or Invoke-MgGraphRequest commands through Graph since something broke my Graph module. Honestly, I appreciate not having to install all the Graph modules on clients to run Azure scripts anymore. IRM works in most cases.
Be careful when downloading or updating Graph modules since it might break your current scripts. I'd recommend installing a specific version instead of just uninstalling everything. This helps ensure you have only the stable version on your system. You can check the version with the most downloads on PSGallery—it usually indicates better stability.
Instead of uninstalling all the Microsoft.Graph modules, try installing a later or specific version. Just nuking everything could mess up other components in your environment. When dealing with assembly issues, testing in a plain PowerShell prompt can help sort things out. Also, version 2.26.1 had some bugs, but I've found that 2.27.x and 2.28.x are stable. Recently, I prefer using just the Graph authentication module and do everything via `Invoke-MgGraphRequest` for simplicity.
We set up local SQL storage for better dashboards and connection to our internal systems and started using the beta endpoint for authentication methods. You can find it on Microsoft documentation. Works smoothly, and you can fetch everything you need in one or a couple of calls!
Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically