Is there any way to get users Login History in SharePoint on-prem 2016? Kindly Suggest.

  • Have you tried given solution? Kindly let me know if any query or need some more help. – Hardik Dec 28 '18 at 6:55
  • Did you tried it? did that worked for you? – Hardik Jan 2 at 7:03

Per my knowledge, there is no OOB solution to get users Login History in SharePoint 2016. However, you can develop a custom auditing solution. You'll need to add custom code to pages which involve login action(recording the login's in your page's code. U)

You can use cookie to be a flag for checking whether there is an user just log in. After the page loaded, if the cookie is null, it suggests that there is an user just log in our site, then we can get this user’s information using JavaScript Object Model and add the information into a custom list. With this list, we can monitor user’s login details. See the reply provided by Dennis from below article:


In addition, below post has a similar issue with you, which may be helpful to you:



User below Powershell to get users from SharePoint.

This script will help save us developers a lot of time in getting all the users from an individual or group. So, here is the script.

  1. Copy the code below to a .ps1 file.
  2. Run the .ps1 file on the SharePoint PowerShell modules.
  3. You don't need to do any update on the script.

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
$Currentime = get-date -format "yyyyMMdd_hhmmtt" $filename = "FarmUsers" $datafile = ("{0}{1}.csv" -f $filename, $Currentime)
$headerfile = "type,user,group,weburl,webtitle" $headerfile | out-file -FilePath $datafile
$iissitedata = get-spwebapplication foreach($farmsite in $iissitedata) {
foreach ($SiteCollection in $farmsite.sites)
write-host $SiteCollection -foregroundcolor Blue
foreach ($web in $SiteCollection.Allwebs)
write-host " " $web.url $web.name "users:" -foregroundcolor yellow
foreach ($usersite in $web.users)
write-host " " $usersite -foregroundcolor white
$data = ("RootUser,{0},-,{1},{2}" -f $usersite, $web.url,$web.name)
$data | out-file -FilePath $datafile -append
foreach ($group in $web.Groups)
Write-host " " $web.url $group.name: -foregroundcolor green
foreach ($user in $group.users)
Write-host " " $user -foregroundcolor white
$data = ("GroupUser,{0},{1},{2},{3}" -f $user, $group, $web.url, $web.name)
$data | out-file -FilePath $datafile -append
} }

Get All Users In A SharePoint 2010/13/16 Farm Using PowerShell Script

Then try following code with loop by passing each user in below code to get last logon from AD.

$dcs = Get-ADDomainController -Filter {Name -like "*"}
$time = 0
foreach($dc in $dcs)
  $hostname = $dc.HostName
  $user = Get-ADUser $User.UserLogin.ToString().split('\\')[1] | Get-ADObject -Properties lastLogon 
  if($user.LastLogon -gt $time) 
    $time = $user.LastLogon
$dt = [DateTime]::FromFileTime($time)
$UserData | Add-Member -type NoteProperty -name "last logged on at" -value $dt

Here $User is the SharePoint User which we found from SharePoint with domain name in it.

  • Thanks for reverting, You have mentioned "get users from SharePoint", means each user who has permission to access SharePoint or each user from AD? Also, how can I get users from SharePoint? – Tezz Chaudhary Dec 28 '18 at 7:34
  • I have edited my answer & added PowerShell code to get users from SharePoint farm. Please check – Hardik Dec 28 '18 at 7:40
  • For your question about users, Yes all users who have access to SharePoint Farm. Not AD Users because we are looking for SharePoint user's last logon – Hardik Dec 28 '18 at 7:42
  • Have you tried it? Did it worked for you? – Hardik Dec 29 '18 at 5:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.