In today’s digital landscape, managing user accounts and monitoring their activities is crucial for organizations to ensure security and maintain an efficient workflow.
With the growing adoption of cloud services like Azure Active Directory (Azure AD), organizations need a reliable way to track user login activities.
Fortunately, PowerShell, a powerful scripting language, combined with graph API, offers an effective solution to generate comprehensive reports on user login information.
In this blog post, I will share the PowerShell Magic using graph API to generate Azure AD User Last Login Report.
Prerequisites for this solution:
Download the solution from below git hub link: (AzureADLastLoginReport.ps1)
https://github.com/VikasSukhija/Downloads
Download the solution from PowerShell Gallery:
https://www.powershellgallery.com/packages/AzureADLastLoginReport
Install-Script -Name AzureADLastLoginReport
Note: You need to setup AzureAD app registration with User.Read.All and AuditLog.Read.All permissions.
Please update the below section of the script as pe your environment:
You can run the script as .\AzureADLastLoginReport.ps1 –
DaysSinceLastLogin 90 -UserType guest -smtpserver smtpserver -from donotrespond@labtest.com -erroremail vikas.s@labtest.com -logrecyclelimit 60
User type can be any of the three options à guest, member or All in case you want report on both.
You can schedule the script in case you want and have the report sent to you every day or every week as per your requirements.
I have run it on more than 50k user Tenant and it just finishes in less than 10 minutes.
Below will be out put format of the script: (one report will be full report and other is based on number of days you have added)
Both reports will be saved in report folder.
I hope you will like this script sample and will be able to utilize it.
Thanks for reading and downloading…
Tech Wizard