Home > Administration, Customization > “The My Site of xxx is scheduled for deletion”

“The My Site of xxx is scheduled for deletion”


We had strange issue (actually it is a feature of SharePoint) that when a user is moved out of organization (when his profile is removed by profile import) a mail is sent out to the manager of the user that ‘The My Site of xxx is scheduled for deletion’ and also it provide site collection admin access to that user’s personal site. And the issue is ‘Privacy’, user my site are personal site and should never be assigned to manager.

So, what we will attempt here is to stop

-> Stop the email sent to the manager

-> Stop the personal from being deleted

-> Stop the assigning the permission to the manager of the user

So, all the above activities are done through a Timer job ‘MySiteCleanUpJob’, which actually deletes the user profile and perform other activities including the above.  And thank fully this can be overwritten through code. Read the below link

http://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.mysiteprofilehandler.aspx

So, we can write a class which inherits IProfileEventInterface and overloads the method ‘PreProfileDeleted‘.  If this method returns true then the profile will be deleted in profile store, and let’s assume we need that to happen and we will return true always.

Once the class is written, what to do next, how to plug in that. Put the following code in a feature receiver

SPService service = SPFarm.Local.Services.GetValue<SPWebService>(string.Empty);
MySiteCleanupJob job = service.JobDefinitions.GetValue<MySiteCleanupJob>(MySiteCleanupJob.DefaultJobName);
job.ProfileDeleteEventHandler = typeof(<<ClassName>>);
job.Update()

So far, everything explained is theoretical, so please try this in your test environment.  Will update the post once this is experimented.

[Update 2] New class cannot be hooked with the above specified way. It can be hooked through “stsadm -o profiledeletehandler” i could not get the equivalent powershell command.

Watch this space.. will update once deployed and tested

[Update 3] Here is the class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.Office;
using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.Office.Server.Diagnostics;

namespace MyCompanyMySiteProfileHandler.MySiteProfileHandler
{
public class MyCompanyMySiteProfileHandler : IProfileEventInterface
{
public virtual bool PreProfileDeleted(UserProfile profile)
{
if (profile == null)
{
return false;
}
else
{
try
{
using (SPSite site = profile.PersonalSite)
{
if (site != null)
{
Microsoft.Office.Server.UserProfiles.MySiteProfileHandler handler = new Microsoft.Office.Server.UserProfiles.MySiteProfileHandler();
//By passing null we do not set the owner for personal site, but still schedule the site for deletion.
//this way reminder email will also not be sent, but the site will be deleted on 14th day from now
handler.SetMySiteOwner(profile, null);
}
}
}
catch(Exception oe)
{
//do something
}
}

//In any case return ture, to make sure the profiles does not remain unattended.
return true;
}

public virtual bool PreProfileDeleted(ServerContext context, UserProfile profile)
{
return true;
}

}
}

Advertisements
  1. July 11, 2012 at 10:28 pm

    Genius! Thanks!

  2. tiwookie
    July 23, 2012 at 4:53 pm

    Hey! Are there any updates regarding the “My Site scheduled for deletion” Issue until now? Is it possible to just modify the notification receiver from the “manager” to just another (assembly) mail address? Nice post btw and thanks!

  3. Nik
    July 27, 2012 at 3:48 am

    Hi Satheesh,

    Is it possible to change the Deletion Message Format. Do have any knowledge about this message where it is located and how actually the receiver works. i have the question in the MS Forums here :
    http://social.technet.microsoft.com/Forums/en-US/sharepointsocialcomputing/thread/bfcfca86-9af5-469e-8cee-40cd9d0c92cd/#bfcfca86-9af5-469e-8cee-40cd9d0c92cd

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: