How to retrieve all the users lastlogon details from entra id

Vishwa Teja Devarakonda 40 Reputation points
2025-02-04T10:59:06.68+00:00

Hi Q&A team,

So i have been trying to retrieve all the users last logon from the microsoft entra id even i tried to retrieve with the help of KQL queries as well so did not solved my issue so please provide me detailed steps to resolve this issue.

Thank you

Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} votes

Accepted answer
  1. Navya 20,180 Reputation points Microsoft External Staff Moderator
    2025-02-05T07:30:42+00:00

    Hi @Vishwa Teja Devarakonda

    Thank you for posting this in Microsoft Q&A.

    I understand you want to retrieve all the users last logon details from Entra ID using PowerShell.

    Can you please try below PowerShell code

    Install-Module Microsoft.Graph
    Import-Module Microsoft.Graph 
    
    Connect-MgGraph -Scopes Directory.Read.All,AuditLog.Read.All
    
    Get-MgUser -All -Property 'UserPrincipalName','SignInActivity','Mail','DisplayName' | Select-Object @{N='UserPrincipalName';E={$_.UserPrincipalName}}, @{N='DisplayName';E={$_.DisplayName }}, @{N='LastSignInDate';E={$_.SignInActivity.LastSignInDateTime}} | Export-Csv -Path C:\usernew1.csv -NoTypeInformation -NoClobber
    

    Hope this helps. Do let us know if you any further queries.

    Thanks,

    Navya.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.


1 additional answer

Sort by: Most helpful
  1. Andy David - MVP 157.8K Reputation points MVP Volunteer Moderator
    2025-02-04T12:18:55.04+00:00

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.