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 within Azure, I have found one guest account where the last login was during 2021, but I need to capture this for all guest accounts?
Is this even possible?
Thanks in advance for any help.
- Here'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}}
- Thiraviam5316Brass 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/
- Here'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}}- coxygtBrass ContributorThanks Vasil,
Have downloaded, just need to check the permissions etc.