Using PowerShell for Microsoft graphs to view the SignInActivity and SignInSessionsValidFromDateTime data?

EnterpriseArchitect 6,061 Reputation points
2023-08-21T14:12:45.4+00:00

How can I view the SignInActivity and SignInSessionsValidFromDateTime?

Because with the below PowerShell command,

Get-MgUser -Filter "signInActivity/lastSignInDateTime le $([datetime]::UtcNow.AddDays(-90).ToString("s"))Z" -All:$true -Property *| Select-Object SignInActivity, SignInSessionsValidFromDateTime

The result is empty like below:

Screenshot 2023-08-21 233006

I can't figure out how to get the information. Is there another way to view this data? Or maybe some other command I can use to access it?

Thanks in advance.

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

Accepted answer
  1. Shweta Mathur 30,301 Reputation points Microsoft Employee Moderator
    2023-08-22T06:52:35.84+00:00

    Hi @EnterpriseArchitect ,

    Thanks for reaching out.

    To get the signIn activity and SignInSessionsValidFromDateTime properties of a user, you need to have the

    AuditLog.Read.All and Directory.Read.All permissions.

    You can try the following PowerShell command to view the SignInActivity and SignInSessionsValidFromDateTime properties of a user:

    Import-Module Microsoft.Graph.Users
    Connect-MgGraph -Scopes "AuditLog.Read.All","Directory.Read.All"
    Get-MgUser | Select-Object UserPrincipalName, SignInActivity,SignInSessionsValidFromDateTime | Export-csv "$((Get-Date -format FileDateTimeUniversal).toString())_signin.csv"
    
    
    

    The above command will export the xml file with below details:

    User's image

    Hope this will help.

    Thanks,

    Shweta


    Please remember to "Accept Answer" if answer helped you.


0 additional answers

Sort by: Most helpful

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.