SharePoint Asked on December 18, 2020
Is there any way to get users Login History in SharePoint on-prem 2016? Kindly Suggest.
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.
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
}
}
$web.Dispose()
}
} }
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.
Answered by Hardik on December 18, 2020
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:
Answered by imp. MSFT on December 18, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP