In this article you will see how to remove the My Site Host location URL in
SharePoint 2010 using PowerShell and the SharePoint object model.
In SharePoint 2010 open the Application Management section in the Central
Administration, click on Manage Service Applications. Click on User Profile
Service application. Go to My Site Settings, click on Setup My Sites.
![]()
In that you could see an option "My Site Host" where the My Site Host site
collection URL will be added.

When you try to remove the URL through UI you will be getting the following
error "The URL you entered could not be validated" as shown in the following

You could remove the My Site Host URL using Powershell and using SharePoint
object model.
Remove My Site Host URL using SharePoint object model:
- Open Visual Studio 2010 by going Start | All Programs | Microsoft Visual Studio 2010 | Right click on Microsoft Visual Studio 2010 and click on Run as administrator.
- Go to File tab, click on New and then click on Project.
- In the New Project dialog box, expand the Visual C# node, and then select the Windows node.
- In the Templates pane, select Console Application.
- Enter the Name and then click OK.
- In the solution explorer, right click on the solution and then click on Properties.
- Select the Application tab, check whether ".Net Framework 3.5" is selected for Target Framework.
- Select the Build tab, check whether "Any CPU" is selected for Platform Target.
- In the solution explorer, right click on the References folder and click on Add Reference.
- Add the following references.
- Microsoft.Office.Server.UserProfiles.dll
- Microsoft.Office.Server.dll
- Microsoft.SharePoint.dll
- System.Web
- Double click on Program.cs and add the
following Namespaces.
1. using Microsoft.SharePoint;
2. using Microsoft.Office.Server.UserProfiles;
- Replace Program.cs with the following code
snippet.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using System.Web;
using Microsoft.Office.Server.UserProfiles;namespace RemoveMySiteHostLocation
{
class Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("http://serverName:60001/sites/TestSiteColl"))
{
SPServiceContext serviceContext = SPServiceContext.GetContext(site);
UserProfileManager upm = new UserProfileManager(serviceContext);
upm.MySiteHostUrl = "";
}
}
}
} - Build the Solution.
- Hit F5.
- Go to Setup My Sites and check My Site
Host URL will be removed successfully.

siva kumarPosted Sep 7, 2012, 2:04 PM
Hi, I have attempted to use your C# code, but it is not working. The MySiteHostUrl is a read-only property and cannot be set. Also please use ServerContext in place of SPServiceContext.