Im fairly new to powershell, and i’m trying to run a simple script which should provice me with the last logon from guest users in our Azure AD.

Get-AzureADUser -All $true -filter "usertype eq 'guest'" | Select UserPrincipalName, DisplayName, LastLogonDate | Export-CSV c:\lastloginguest.csv

Im getting the UPN and Displayname as requested, but it doens’t show the lastlogonDate (or lastloginTime etc etc).

What am i doing wrong here?

8 Spice ups

You can try this:

Get-AzureADUser -All $true -filter "usertype eq 'guest'" | select UserPrincipalName,DisplayName,RefreshTokensValidFromDateTime | Export-CSV c:\lastloginguest.csv

Its not exactly the last logon but very close to ist :wink:
User profile attributes in Azure Active Directory B2C | Microsoft Learn

Those cmdlets are going to die in a few months , you need to use the ones based on Microsoft Graph instead. Also, it sounds like you want the " SignInActivity " attribute which is exposed through Graph anyway.

notice the below steps are from the preview version the default steps may differ slightly

portal.azure.com

azure-active-directory

users

sign-in logs

adjust your date range, status (if you want)

add filter (User type (guest))

you have 2 views that come up, interactive and non-interactive.

you can download to csv or json if you wish