Home > OS >  Getting all users and their last login via graph API
Getting all users and their last login via graph API

Time:03-17

I am trying to export all users data including last login date. I am following this article:

enter image description here

However signInActivity is always null for all users. Is it not possible to get all users with graph API including last signin?

CodePudding user response:

Two key points is that first you need to have the AuditLog.Read.All permission scope added to your application permissions. Second, SignInActivity is a part of the "beta" version of the Microsoft Graph SDK API. You have to change your Microsoft Graph profile to the "beta" version before you connect in order to access the beta version of the API I find it's easier to use the new Microsoft Graph PowerShell SDK PowerShell module to get this information:

Select-MgProfile -Name "beta"
Connect-MgGraph -Scopes 'AuditLog.Read.All'
$user = Get-MgUser -UserId '123-...-abc123' -Property 'SignInActivity'
$user.SignInActivity.LastSignInDateTime

CodePudding user response:

The $ in the MS Graph REST URLs is required as part of the query string. You'll need to either escape it with backtick `, or use single quotes:

$ApiUrl = "https://graph.microsoft.com/beta/users?`$select=displayName,signInActivity"
  • Related