1

I have some user accounts in the user profile db that I need to delete using powershell. user accounts are jsmith; bsimmons; boilers; nholmber, bburton

  • I have a very similar need where I need to delete all the tstUserXX (where xx is number from 44 to 78) users. Anyone?? – Kevin Short Nov 9 '15 at 13:50
1

Practically in the real case scenario, setting up the My Site by removing the access of the respective user is enough. If there's a need to backup the site, then do it before removing or locking the site. For the User Profile's side, we need to keep My Site Cleanup job running properly. Although the name is My Site Cleanup job, it does everything, from removing User Profile, till removing My Site.

There's a good article from one of my favourite SharePoint enthusiast, Spencer Harbar, about User Profile Deletion.

Basically My Site will do these:

  1. Removing User Profiles that are marked for deletion
  2. Delete the User Profiles' My Site that are marked for deletion directly, if there's no manager assigned to his/her Active Directory's Manager attribute (generally this will be treated as that person's direct manager.
  3. If the user has Manager attribute set, it will assign his/her direct manager as secondary contact, and notify direct manager that the My Site will be deleted in 14 days.
  4. Email the direct manager again after 11 days (3 days before deletion), that My Site will be deleted.
  5. Total deletion on the 14th days.

There's requirement to let My Site Cleanup job to work properly. It requires My Site Host to be configured. If it is not configured, then the job which includes deletion of User Profile will not work.

System will trigger and set an account marked for deletion if you do one of these:

  1. Account is deleted
  2. Account is disabled
  3. SharePoint User Profile connection is changed with additional filter or recreated
  4. Account is moved out that is out of OU, and OU is not part of SharePoint User Profile sync

That is why we don't need to do additional jobs, as long as we have the SharePoint configured properly. Basically this timer job will run arround 59 minutes (by default). You can change the amount of time or directly run the timer job.

Same question asked in Servefault check this link

For Reference

Account Deletion and SharePoint 2010 User Profile Synchronization

Inside the SharePoint 2010 My Site Cleanup Timer Job

0

Found the solution on Falak Mahmood MSDN blog. https://gallery.technet.microsoft.com/office/Delete-all-User-Profiles-fa4e1428

#Add SharePoint PowerShell SnapIn if not already added 
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) { 
    Add-PSSnapin "Microsoft.SharePoint.PowerShell" 
} 


$site = new-object Microsoft.SharePoint.SPSite("http://skvkfm-it01/");  
$ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site);  

#Get UserProfileManager from the My Site Host Site context 
$ProfileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)    
$AllProfiles = $ProfileManager.GetEnumerator()  

foreach($profile in $AllProfiles)  
{  
    $DisplayName = $profile.DisplayName  
    $AccountName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value  

    #Do not delete setup (admin) account from user profiles. Please enter the account name below 
    if($AccountName -ne "Domain\MySiteSVApp") 
    { 
        $ProfileManager.RemoveUserProfile($AccountName); 
        write-host "Profile for account ", $AccountName, " has been deleted" 
    } 

}  
write-host "Finished." 
$site.Dispose() 
0

The thing is O365 does not give us: Microsoft.Office.Server.UserProfiles.UserProfileManager.

It only gives us: Microsoft.SharePoint.Client.UserProfiles.PeopleManager

The only remove methods I got are:

  1. HardDeleteUserProfile: which is only read only (value shows true/false).
  2. RemoveSPUserInformation: which I was not able to use.

Not sure if we are able to do such thing using PowerShell, contacting to Microsoft team for this. Will keep you guys posted if anything changes.

Cheers,

J

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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