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.









Thanks for the useful info. It’s so interesting
thanks!!!
was looking for this! Great script
MAN YOU ROCK , saved our day …kudos