How to retrieve all the users lastlogon details from entra id

Vishwa Teja Devarakonda 0 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

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,793 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
23,112 questions
0 comments No comments
{count} votes

2 answers

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

  2. Navya 14,985 Reputation points Microsoft Vendor
    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.


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.