Office365/AzureAd last logon

Iron Contributor

I ingest the Office365 unified audit log and AAD Signin Logs into Azure log analytics, and now use log analytics for almost all of my search requirements across Office365, Security, Audit etc..  


Given the difficulty for IT Admins to audit user inactivity these days, (seen here as the "Last Logon" date in Exchange Online is reliable, and it doesn't account for the other Office365 products.  I know the Management API has some helpful attributes but the lastlogon date only allows you to go back 30 days.. which is not enough.  Yes i understand, i can pull down data over a 3 month period, then crunch that together and roll my own last logon date from that, but i'd prefer not to.


The Azure AD Sign in logs do provide all, ... nearly all the necessary data to detect user inactivity, but i need some help.


I am using the below query against the SigninLogs table, but i cannot work out of find the query syntax for "is NOT greater than 90 days ago".  There does not seem to be an operator for "!>" or "not >".

| where TimeGenerated < ago(90d) 
| where TimeGenerated "is NOT greater than 90 days ago"
| where UserPrincipalName endswith ""
| where ResultType == 0
| project UserPrincipalName
Any help to make this query work would be amazing!
2 Replies


I am not sure if I can understand the request exactly but I will try to answer. I would like to first make a note that TimeGenerated is the time the log was generated. Keep in mind that there might be a different date/time column that shows the date of the login activity. With the above query you have pasted and specifically

| where TimeGenerated < ago(90d) 

you are actually taking all records that have happened before 90 days. So I think this is what you are actually requested.

You can do also additional things like

| where TimeGenerated < ago(90d) and TimeGenerated > ago(120d)

To do exact time frame.

Also to note that by default Log Analytics stores data for 31 days. If you want to go beyond you will need to extend the retention period of your Log Analytics workspace.

Let me know if this helps.

@Stanislav Zhelyazkov 


I believe they are asking about correlating the office365 audit logs to azure ad auditg logs, more specifically sign in attributes. The problem is the office 365 logs do not expose any true sign in event to correlate the two data sources from what I can tell.