O365 last logon

%3CLINGO-SUB%20id%3D%22lingo-sub-227418%22%20slang%3D%22en-US%22%3EO365%20last%20logon%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-227418%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20trying%20to%20extract%200365%20last-logon.%20is%20there%20is%20any%20other%20way%20other%20than%20mailboxstatistics%20cmdlet%20in%20powershell.%20This%20command%20doesnt%20help%20me.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThings%20i%20have%20tried.%3C%2FP%3E%3CP%3E1.%20Search-UnifiedAuditLog%20-StartDate%2005%2F14%2F2018%20-EndDate%2008%2F12%2F2018%20-RecordType%20AzureActiveDirectoryStsLogon%2CSharePointFileOperation%2CYammer%2Cexchangeitem%2C%20exchangeitemgroup%20-userids%20%24email%20-resultsize%205000%20%7C%20Sort-Object%20creationdate%20-Descending%26nbsp%3B%20%7C%20ft%20operations%2C%20userids%2C%20creationdate%20-autosize%20-Wrap%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E2.%26nbsp%3BSearch-UnifiedAuditLog%20-UserIDs%20%24SearchMailbox%20-StartDate%20%24StartTime%20-EndDate%20%24EndTime%20-Operations%20%22UserLoggedIn%22%2C%22User%20signed%20in%20to%20mailbox%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E3.%20download%20the%20activity%20report%20from%20portal.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20there%20is%20any%20other%20better%20way%20to%20get%20the%20last%20actual%20logon.%20thats%20includes%20any%20office365%20products.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20there%20is%20any%20other%20way%20trigger%20the%20activity%20report%20via%20powershell%2F%20or%20get%20data%20activity%20data%20by%20powershell%20for%20a%20user.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eany%20help%20will%20be%20appreciated.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethanks%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-227418%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Eoffice365%20activity%20report%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-227529%22%20slang%3D%22en-US%22%3ERe%3A%20O365%20last%20logon%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-227529%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20Bupeshkumar%20Rajendiran%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFinding%20a%20last-logon%20using%20the%20audit%20log%20is%20quite%20challenging.%20If%20you%20go%20with%20the%20PowerShell%20then%20you%20need%20to%20retrieve%26nbsp%3Ball%20the%20data%20and%20compute%20the%20statistics%20by%20iterating%20the%20result%20or%20you%20may%20store%20the%20data%20in%20a%20database%20which%20you%20can%20run%20a%20query%20against.%20Also%2C%20note%20that%20you%20can%20find%20the%20last%20login%20information%20only%20if%20the%20user%20logged%20in%20the%20past%2090%20days%20as%20Microsoft%20only%20preserve%20the%20audit%20log%20for%20last%2090%20days%20by%20default.%20Preserving%20beyond%20this%20limit%20is%20also%20quite%20challenging.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20believe%20you%20are%20looking%20for%20a%20report%20%3CA%20href%3D%22http%3A%2F%2Fdemo.admindroid.com%2F%23%2Faudit%2Fazure%2Freports%2F20164%2F1%2F20%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Elike%20this%3C%2FA%3E.%20Instead%20of%20developing%20the%20solution%20on%20your%20own%2C%20the%20better%26nbsp%3Bway%20is%20to%20use%20the%20pre-built%20solution%20which%20takes%20care%20of%20preserving%20the%20data%20over%20the%20retention%20limit%2C%20timely%20sync%2C%20etc.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-227422%22%20slang%3D%22en-US%22%3ERe%3A%20O365%20last%20logon%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-227422%22%20slang%3D%22en-US%22%3E%3CP%3EThose%20are%20the%20methods%20that%20expose%20the%20correct%20data.%20If%20you%20are%20looking%20to%20automate%20it%2C%20PowerShell%20should%20do%20the%20trick%2C%20and%20for%20the%20report%20you%20can%20use%20the%20Graph%20API%3A%20%3CA%20href%3D%22https%3A%2F%2Fdeveloper.microsoft.com%2Fen-us%2Fgraph%2Fdocs%2Fapi-reference%2Fv1.0%2Fapi%2Freportroot_getoffice365activeuserdetail%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdeveloper.microsoft.com%2Fen-us%2Fgraph%2Fdocs%2Fapi-reference%2Fv1.0%2Fapi%2Freportroot_getoffice365activeuserdetail%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

I am trying to extract 0365 last-logon. is there is any other way other than mailboxstatistics cmdlet in powershell. This command doesnt help me.

 

Things i have tried.

1. Search-UnifiedAuditLog -StartDate 05/14/2018 -EndDate 08/12/2018 -RecordType AzureActiveDirectoryStsLogon,SharePointFileOperation,Yammer,exchangeitem, exchangeitemgroup -userids $email -resultsize 5000 | Sort-Object creationdate -Descending  | ft operations, userids, creationdate -autosize -Wrap

 

2. Search-UnifiedAuditLog -UserIDs $SearchMailbox -StartDate $StartTime -EndDate $EndTime -Operations "UserLoggedIn","User signed in to mailbox"

 

3. download the activity report from portal.

 

Is there is any other better way to get the last actual logon. thats includes any office365 products.

 

Is there is any other way trigger the activity report via powershell/ or get data activity data by powershell for a user.

 

any help will be appreciated.

 

thanks

 

2 Replies
Highlighted

Those are the methods that expose the correct data. If you are looking to automate it, PowerShell should do the trick, and for the report you can use the Graph API: https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/reportroot_getoffice365activ...

Highlighted

Hello Bupeshkumar Rajendiran,

 

Finding a last-logon using the audit log is quite challenging. If you go with the PowerShell then you need to retrieve all the data and compute the statistics by iterating the result or you may store the data in a database which you can run a query against. Also, note that you can find the last login information only if the user logged in the past 90 days as Microsoft only preserve the audit log for last 90 days by default. Preserving beyond this limit is also quite challenging.

 

I believe you are looking for a report like this. Instead of developing the solution on your own, the better way is to use the pre-built solution which takes care of preserving the data over the retention limit, timely sync, etc.