6

Is there a easy way to remove (delete) all personal sites and recreate them all over again? I also want to delete them from the sql.

I've tried to delete personal sites and run my site clean up job but it seems not to be removed from the DB. I know I have to wait ~14 days and then ~11 days before they get removed from the DB. Is there a way to force delete them without waiting?

The reason I want to delte the db entry is to not get in a situation that the db runs out of space.

The best way would be to recreate the entire web application but I can't do that because of integration to all other systems.

When deleting personal mysites I run this lines..

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

    if($profile.PersonalSite -ne $Null)
    {
       $profile.PersonalSite.Delete()
       write-host $AccountName , " personel site deleted successfully" -ForegroundColor Green
    }
}
4
  • The thread you refers to do not force delete them from the db, without waiting ~25 days
    – Plexus81
    Jan 4, 2016 at 9:41
  • 1
    Why not just compile a list of MySites based on managed path and/or Site Template ID (MYSITE#0, IIRC)? From there, use Remove-SPSite w/o -GradualDelete. You can then go through the UPM OM to clear out the Personal Site URL.
    – user6024
    Jan 4, 2016 at 15:33
  • @TrevorSeward I did almost the same .. and it worked ok.
    – Plexus81
    Jan 12, 2016 at 14:43

1 Answer 1

0

Can you try with the below PS code for deleting the mysites?

 Add-PSSnapin "Microsoft.SharePoint.PowerShell"

 [Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
 $mysiteHostUrl = "http://my"
 $mysite = Get-SPSite $mysiteHostUrl
 $context = [Microsoft.Office.Server.ServerContext]::GetContext($mysite)
 $upm =  New-Object    
 Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
 $AllProfiles = $upm.GetEnumerator()
 foreach($profile in $AllProfiles)
 {
 $DisplayName = $profile.DisplayName
  $AccountName = 
      $profile[[Microsoft.Office.Server.UserProfiles.
        PropertyConstants]::AccountName].Value  
  if($profile.PersonalSite -ne $Null)
   {
   $profile.PersonalSite.Delete()
   write-host $AccountName , " personal site deleted successfully"
    }
  }
  $mysite.Dispose();
4
  • I've got almost the same code .. but this code does not delete the personal site from the db straight away.. you have to wait ~25 days before sharepoint removes the personal site entry from the db
    – Plexus81
    Jan 4, 2016 at 9:47
  • Manipulating the entry directly from content db is not supported by MSFT. But can you look at the All_Docs table from your web app's content DB with your SS Mgmnt Studio? I hope you would be able to get the row in that table related to mysite.
    – samolpp2
    Jan 4, 2016 at 10:46
  • Can you check this link also: sharepoint-community.net/profiles/blogs/deleting-orphan-mysites
    – samolpp2
    Jan 4, 2016 at 10:52
  • Through SSMS : demantprasad.com/2013/09/… "select count(*) as 'Total Site Collection' from sites" . The below sql can get the web title and you would be able to get the mysite title and delete it from Content DB . "select Title as 'Root Web Title', Sites.RootWebId, Sites.Id as 'Site Collection ID' from webs inner join Sites on Webs.Id = Sites.RootWebId" . Hope this helps
    – samolpp2
    Jan 4, 2016 at 11:19

Your Answer

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

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