3

My network admin have deactivated a lot of users from the Active Directory, and recreated them using the same username but with a different OU, Now the SP 2010 does not recognize these users or their Permissions unless i manually Remove them from the "Members" group i created and manually add them back (then they get recognized noticeable by their display name changing).

Since i have a lot of different site collections which these users can be in any one of them i tried using the object model to go through all the site collections under the web application and remove and re-add each user permissions like so:

SPSite site = new SPSite("http://localhost:47700/Divisions/100/");
SPWebApplication webApp = site.WebApplication;

foreach (SPSite currentSiteCollection in webApp.Sites)
{
    // user is struct i created to keep the user info.
    List<user> members = new List<user>();

    SPWeb web = currentSiteCollection.RootWeb;

    try
    {
        SPGroup membersGroup = web.SiteGroup["Members"];

        foreach (SPUser currentUser in membersGroup.Users)
        {
            user userData;
            userData.login = currentUser.LoginName;
            userData.email = currentUser.Email;
            userData.name = currentUser.Name;
            userData.notes = currentUser.Notes;

            members.Add(userData);
        }

        foreach (user currentMember in members)
        {
            membersGroup.Users.Remove(currentMember.login);
        }

        membersGroup.Update();

        foreach (user currentMember in members)
        {
            membersGroup.Users.Add(currentMember.login, currentMember.email, currentMember.name, currentMember.notes);
        }

        membersGroup.Update();
    }
    catch (Exception ex)
    {
    throw ex;
    }

For some reason it dosen't work. Does anyone have any idea why it doesn't work? How to make it work? or any better idea of how to to it?

Thanks in advance, Itay.

1
  • 4
    If they physically deleted the users from AD and then added them new again then the issue you are facing is not that the OU changed, it is that the SID changed and these are, for all intents and purposes, completely new users despite having the same user name. You will have to resync your User Profiles in order to pick up the 'new' users but I'm not sure how it will handle the old login names but with a different SID. Perhaps someone with more UPS background can assist.
    – Dave Wise
    Commented May 3, 2013 at 14:23

1 Answer 1

1

Dave is right. You might can try to use the migrateuser functionality to see if that will fix the sids for you. Stsadm or powershell

http://blogs.msdn.com/b/sowmyancs/archive/2012/01/07/migrate-users-groups-powershell-script.aspx

1
  • 1
    It worked except for one weird problem described Here
    – Itay Weiss
    Commented May 4, 2013 at 17:30

Your Answer

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

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