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

EnterpriseArchitect 6,391 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

Answer accepted by question author
Shweta Mathur 30,461 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.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

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