0

I need to get all currently active (not removed users) from a site. I have the following JS that gets all the users but some of them are old users that have been removed from the site (still exists in AD). How can I ensure the users returned are valid users with at least read access?

(function(){
var clientContext;
var users;

$(document).ready(function () {
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getUsers);
});

function getUsers() {

    var clientContext = new SP.ClientContext.get_current();
    var web = clientContext.get_web();
    var users = web.get_siteUsers();


    clientContext.load(users);
    clientContext.executeQueryAsync(RetrievedUsers, ExecutionFailed);

    function RetrievedUsers(sender, args) 
    {
        for(var i = 0; i < users.get_count();i++)
        {
            var user = users.getItemAtIndex(i);
            var name = user.get_loginName();
            alert(name);
        }
    }

    function ExecutionFailed(sender, args) 
    {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }     
}
})();
2
  • I came across this article written for 2007/2010. It a PS script to remove alerts from users who no longer exist in AD. geekswithblogs.net/kjones/archive/2012/04/24/149404.aspx
    – MickB
    May 20, 2015 at 15:29
  • Thank you but that doesnt help me. I edited my text to make it clearer that I am looking for valid users with read access.
    – David
    May 21, 2015 at 8:10

1 Answer 1

0

Web.SiteUsers usually contains all users, that do have explicit permissions somewhere in the Web. Are you sure that there is no Point where permission inheritance is broken up and the users were granted explicit permissions?

Finally, you can´t be sure that the users you get have the permissions you want to check. You can only check permissions, which the user is assigned explicitly on. If a permission is assigned by using a AD or SP-Group the user is member of, SharePoint won´t tell you that by Default. So, after all, if you want to be sure you would have to check all the AD-Groups the user is member of too, which you would not be able to do using Javascript-CSOM.

1
  • You can test yourself on a brand new site it will show all current and past users. What I have done in the meantime until I find a better solution is to get all groups and all their users and then I check all the users if they exist in one of those groups. Can be changed to check specific PermissionKind if I need to know or check for specific permissions.
    – David
    May 21, 2015 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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