The other day I sat together with one of my colleagues who is working with setting up a quite large Moss farm. Initially they had imported all profiles from AD to see that everything worked as i should. But now, when they are about to go live they needed to do a new import that did not include all profiles. In the first one they did get all admin accounts etc. ending up with +200 000 profiles.

In Central Administration it’s not possible to delete the whole list of profiles or do any batch job to delete more then one at the time. So what we did was that we created a small PowerShell script that enumerates through all the imported profiles and then deletes them.

This is how it looks:

 

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Office.Server”) [System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Office.Server.UserProfiles”)

$SSP = “Shared Service Provider – 8080″

$ServerContext = [Microsoft.Office.Server.ServerContext]::GetContext($SSP)

$UserProfileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServerContext)

$Profiles = $UserProfileManager.GetEnumerator()

foreach ($oUser in $Profiles ) {

$UserProfileManager.RemoveUserProfile($oUser.item(“AccountName”));

}

First we connect to the Site and the SSP using the GetContext, note that you need to change the SSP variable to the name of your SSP.

We then crate a new UserProfileManager object. The UserProfileManager is they way to work with the user profiles.

When that is done you can just loop through the profiles and delete each and everyone of them.

When we did this we could then modify the import of user profiles so that we got only those we needed.



  1. SharePoint Guy on Monday 29, 2009

    Thanks for the useful info. It’s so interesting

  2. daan on Monday 29, 2009

    thanks!!!
    was looking for this! Great script

  3. SharepOint NEw Bie on Monday 29, 2009

    MAN YOU ROCK , saved our day …kudos

  4. me on Monday 29, 2009

    just go into the sql database for ssp and delete users from the Userprofile_full table, no need to mess with scripts



Subscribe without commenting