How to find the last 10 login user IDs and timestamps in SharePoint 2016 on premises using PowerShell

C Pradeep 0 Reputation points
2024-08-13T05:24:15.6466667+00:00

we are using SharePoint 2016 On premises version in our organization,

we need usage details of the sites in sharepoint along with the last accessed time & user Id details. we need to know who viewed the sites and when they accessed it last time,their user ID and timestamp.

Helps us how to find, if any script is there, please share.

SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,616 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,551 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ling Zhou_MSFT 17,550 Reputation points Microsoft Vendor
    2024-08-13T07:42:21.44+00:00

    Hi @C Pradeep,

    Thank you for posting in this community.

    Please try to use the Merge-SPUsageLog cmdlet. Here is an example PowerShell script that retrieves the last 10 login user IDs and timestamps:

    Merge-SPUsageLog -StartTime (Get-Date).AddDays(-1) -EndTime (Get-Date) | ? { $_.EventId -eq "14" } | Select-Object -First 10 | Select-Object UserDisplayName, Timestamp | Sort-Object Timestamp -Descending
    

    This script retrieves the usage logs from the last day, filters for login events (EventId 14), selects the first 10 results, and sorts them by timestamp in descending order. The output will include the user display name and timestamp for each login event.

    References:

    Hope this helps.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

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