Retrieve the most recent sign-in event for a user from audit logs when the tenant lacks Entra ID Premium licensing.
Complexity: Intermediate. Impact: security + audit + identity + troubleshooting.
Why use this workflow
Administrators frequently need to confirm when a user last signed in: to investigate account compromise, check whether a departing employee has been active, audit dormant accounts, or triage sign-in complaints. The obvious source is the signInActivity property on the user object in Microsoft Graph, but that property requires an Entra ID Premium P1 or P2 license. Tenants without Premium receive an HTTP 403 error (Tenant is not a B2C tenant and doesn't have premium license) when they query it.
The auditLogs/signIns endpoint is available with reduced retention on tenants without Premium. This workflow shows how to fall back to the sign-in logs to answer the same question, and how to interpret the result, including common failure codes such as 50057 (account disabled).
Run this workflow when you need to know a user's last sign-in, when you investigate a help desk ticket such as why can't I sign in?, or when you audit account activity on a tenant without Premium.
Expected outcomes
- The user's most recent sign-in event (successful or failed) with timestamp, application, IP address, and location.
- The sign-in result, including any failure reason and error code, so you know whether the user actually got in.
- A reusable pattern for querying sign-in logs by user ID that works regardless of license tier.
- Next-step guidance (for example, the account is disabled, so offer to re-enable it, or repeated failures from an unknown IP address, so consider revoking sessions and resetting the password).
Risks and considerations
Retention limits
The auditLogs/signIns endpoint retains a limited window of data: 30 days on Premium tenants and 7 days on tenants without Premium. If the user has not signed in recently, the log may be empty. This does not mean that they never signed in, only that the sign-in was outside the retention window.
Failed sign-ins are still sign-ins
The most recent event may be a failed attempt (disabled account, wrong password, MFA failure). Always check the status.errorCode and status.failureReason fields before you conclude that the user was active. A non-zero errorCode means that the sign-in did not succeed.
Non-interactive sign-ins
The default signIns endpoint returns interactive sign-ins. Service principal sign-ins, token refreshes, and some background authentications appear in separate collections (nonInteractiveUserSignIns, servicePrincipalSignIns). For a complete picture, query those too.
Privacy and compliance
Sign-in logs contain IP addresses and geolocation. Treat them as personal data under regulations such as GDPR and CCPA. Do not export or forward them outside approved IT channels without a documented reason.
Do not confuse this with mailbox activity
A user with no recent sign-ins may still receive email and calendar invitations. If you are evaluating whether an account is truly dormant, also check mailbox last activity through the Exchange reports or the Graph usage reports.
Required permissions
| Permission | Why it's needed |
|---|---|
| AuditLog.Read.All | Required to read sign-in events from /auditLogs/signIns |
| Directory.Read.All | Required to resolve a display name or UPN to a user object ID before you query the logs |
| User.Read.All | Alternative to Directory.Read.All for looking up the user record |
Ask Dex
Paste the prompt into a Dex conversation.
Prompt for IT admins
When did {user} last sign in? If the tenant doesn't have Entra ID Premium, fall back to the sign-in audit logs and tell me the timestamp, app, location, and whether it succeeded or failed.
Manual steps (admin center)
The sign-in logs page is available in the Entra admin center even without Premium, with reduced retention. This is the fastest path for a one-off lookup.
Step 1: Open the Entra admin center
- Sign in to the Microsoft Entra admin center as a Global Reader, Security Reader, or Global Administrator.
- Go to Identity > Users > All users.
Step 2: Find the user
- In the search box, enter the user's display name or UPN (for example,
adrian@contoso.com). - Select the user's name to open their profile.
- Note the Account enabled status at the top. A disabled account explains why recent sign-ins may be failing.
Step 3: View sign-in logs for this user
- In the user's profile, select Sign-in logs from the left menu (under Activity).
- The default view shows interactive sign-ins from the last 24 hours. Change the Date filter to Last 7 days or Last 30 days (30 days requires Premium).
- Sort by Date in descending order. The top row is the most recent sign-in attempt.
Step 4: Inspect the event
- Select the top row to open the sign-in details panel.
- Review Date, Status (Success or Failure), Application, IP address, Location, and, if the sign-in failed, the Sign-in error code and Failure reason.
- Switch between the Interactive, Non-interactive, Service principal, and Managed identity tabs if you need a full picture.
Step 5: Export if needed
Use Download > CSV at the top of the logs grid to export the filtered results for a ticket or audit record.
Microsoft Graph API
This pattern works on any tenant and does not require Entra ID Premium.
Step 1: Resolve the user to an object ID
GET https://graph.microsoft.com/v1.0/users?$filter=startswith(displayName,'{displayName}')&$select=id,displayName,userPrincipalName,accountEnabledExample response:
{
"value": [
{
"id": "6ec10ce2-e41b-46cb-bda2-2900a8965720",
"displayName": "Adrian Example",
"userPrincipalName": "adrian@contoso.com",
"accountEnabled": false
}
]
}Capture id. You use it as the userId filter in the next call.
Step 2: Attempt signInActivity (optional, Premium only)
If your tenant does have Entra ID P1 or P2, the single-call path is:
GET https://graph.microsoft.com/v1.0/users/{userId}?$select=signInActivityOn tenants without Premium, this returns HTTP 403 with the message Tenant is not a B2C tenant and doesn't have premium license. That is your cue to fall back to Step 3.
Step 3: Query the sign-in audit log
GET https://graph.microsoft.com/v1.0/auditLogs/signIns?$filter=userId eq '{userId}'&$orderby=createdDateTime desc&$top=1&$select=createdDateTime,userDisplayName,userPrincipalName,appDisplayName,status,ipAddress,locationExample response:
{
"value": [
{
"createdDateTime": "2026-03-31T13:52:12Z",
"userDisplayName": "Adrian Example",
"userPrincipalName": "adrian@contoso.com",
"appDisplayName": "Microsoft Authentication Broker",
"ipAddress": "2607:fb91:...",
"status": {
"errorCode": 50057,
"failureReason": "The user account is disabled."
},
"location": { "city": "Austin", "state": "Texas", "countryOrRegion": "US" }
}
]
}Interpreting the result
status.errorCode == 0: successful sign-in.status.errorCode != 0: failed sign-in. Common codes:50057(account disabled),50126(invalid credentials),50074(MFA required),50053(account locked).- Empty
valuearray: no sign-ins within the retention window.
Useful variants
- Last 10 events: change
$top=1to$top=10. - Only successful sign-ins: add
and status/errorCode eq 0to the filter. - Non-interactive sign-ins (token refreshes, background authentication): query
/auditLogs/signIns?$filter=userId eq '{userId}' and signInEventTypes/any(t:t eq 'nonInteractiveUser').
PowerShell
The Microsoft.Graph PowerShell SDK wraps both Graph calls shown above. This is the cleanest option for repeated lookups or for embedding in a help desk workflow.
Step 1: Install and connect
# One-time install
Install-Module Microsoft.Graph -Scope CurrentUser
# Connect with the scopes needed for user lookup and sign-in log reads
Connect-MgGraph -Scopes "User.Read.All", "AuditLog.Read.All"Step 2: Resolve the user
$user = Get-MgUser -Filter "userPrincipalName eq 'adrian@contoso.com'" -Property Id,DisplayName,UserPrincipalName,AccountEnabled
$userStep 3: Query sign-in logs
$lastSignIn = Get-MgAuditLogSignIn `
-Filter "userId eq '$($user.Id)'" `
-Top 1 `
-Sort "createdDateTime desc"
$lastSignIn | Select-Object CreatedDateTime, AppDisplayName, IpAddress, `
@{n='City';e={$_.Location.City}}, `
@{n='Result';e={if($_.Status.ErrorCode -eq 0){'Success'}else{"Failed ($($_.Status.ErrorCode): $($_.Status.FailureReason))"}}}Step 4: Handle the Premium-only path
On a Premium tenant, Get-MgUser -Property SignInActivity returns the same data in a single call. To cover both cases in one script, wrap that call in try/catch and fall back to Get-MgAuditLogSignIn when you receive a 403 error.