2

Is there a way to find out when a user last logged into SharePoint using CSOM?

2

powershell

http://admin-sharepoint.blogspot.co.uk/2013/08/get-users-last-logon-time-and-date.html

C#

public DateTime Get(string attr, string UserName)
    {

        DomainConfiguration domainConfig = new DomainConfiguration();
        using (new SPMonitoredScope("AD Properties"))
        {
            using (DirectoryEntry domain = new DirectoryEntry("LDAP://" + domainConfig.DomainName, domainConfig.UserName, domainConfig.Password))
            {
                //DirectorySearcher searcher = new DirectorySearcher(domain, "(|(objectClass=organizationalUnit)(objectClass=container)(objectClass=builtinDomain)(objectClass=domainDNS))");
                DirectorySearcher searcher = new DirectorySearcher(domain);
                searcher.PageSize = 1000;
                searcher.Filter = "(SAMAccountName='" + UserName + "')";
                //searcher.Filter = "(|(objectCategory=group)(objectCategory=person))";
                searcher.Filter = "(&(objectClass=user) (cn=" + UserName + "))";
                var user = searcher.FindOne();
                DateTime LastLogon = DateTime.FromFileTime((Int64)user.Properties["lastLogon"].Value);
                return LastLogon;
            }
        }
    }

https://stackoverflow.com/questions/13796547/how-to-get-last-login-details-time-for-all-users

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.