Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
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 May 3 '13 at 14:23
add comment

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer
1  
It worked except for one weird problem described Here –  itaywss May 4 '13 at 17:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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