Just completed a new script in my Office repo:
https://github.com/directorcia/Office365/blob/master/m365-inactiveusers-get.ps1
and the documentation is here:
https://github.com/directorcia/Office365/wiki/Microsoft-365-Inactive-Users-Check-Script
The m365-inactiveusers-get.ps1 script is a comprehensive PowerShell tool designed to analyze user activity within Microsoft 365 tenants. It identifies inactive users, tracks license assignments, monitors external/guest user access, and generates detailed reports to help administrators maintain security and optimize license usage.