Forum Discussion
coxygt
Oct 12, 2022Brass Contributor
Last Login dates for all Guests using PowerShell
So I need to be able to report on all guest accounts on my companies tenant, to see the last time they logged on. AzureADSignin Logs are no good as they only cover last 30 days, I know somewhere wit...
- Oct 12, 2022Here's a sample script on that that I wrote a while back: https://www.michev.info/Blog/Post/2968/reporting-on-users-last-logged-in-date-in-office-365
To do it via PowerShell, use the Graph SDK:
Select-MgProfile beta
Get-MgUser -All:$true -Filter {userType eq 'Guest'} -Property UserPrincipalName,SignInActivity | select UserPrincipalName,@{n="LastLoginDate";e={$_.signInActivity.lastSignInDateTime}}
Thiraviam5316
Jun 27, 2023Brass Contributor
coxygt You can easily find the last logon details of a guest users using a single cmdlet 'Get-MgUser'.
Get-MgUser -All -Filter "UserType eq 'Guest'" -Property SignInActivity | Select-Object userprincipalname -ExpandProperty SignInActivity | Format-List
For additional information about guest users management, check: https://m365scripts.com/microsoft365/a-quick-approach-to-manage-guest-users-in-microsoft-365-using-powershell/