Remove the My Site Host Location URL in SharePoint 2010


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.

Share1.gif

In that you could see an option "My Site Host" where the My Site Host site collection URL will be added.

Share2.gif

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

Share3.gif

You could remove the My Site Host URL using Powershell and using SharePoint object model.

Remove My Site Host URL using SharePoint object model:
 

  1. 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.
  2. Go to File tab, click on New and then click on Project.
  3. In the New Project dialog box, expand the Visual C# node, and then select the Windows node.
  4. In the Templates pane, select Console Application.
  5. Enter the Name and then click OK.
  6. In the solution explorer, right click on the solution and then click on Properties.
  7. Select the Application tab, check whether ".Net Framework 3.5" is selected for Target Framework.
  8. Select the Build tab, check whether "Any CPU" is selected for Platform Target.
  9. In the solution explorer, right click on the References folder and click on Add Reference.
  10. Add the following references.

    • Microsoft.Office.Server.UserProfiles.dll
    • Microsoft.Office.Server.dll
    • Microsoft.SharePoint.dll
    • System.Web
     
  11. Double click on Program.cs and add the following Namespaces.

    1. using Microsoft.SharePoint;
    2. using Microsoft.Office.Server.UserProfiles;
     
  12. 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 = "";               
                }
            }
        }
    }

  13. Build the Solution.
  14. Hit F5.
  15. Go to Setup My Sites and check My Site Host URL will be removed successfully.

Remove My Site Host URL using Powershell:

Steps Involved:


1. Create the input xml file which contains the inputs to remove My Site Host Location URL.
2. Create ps1 file which contains the script to remove My Site Host Location URL.

RemoveMySiteHostURL.xml

<?xml version="1.0" encoding="utf-8" ?>
<RemoveMySiteHostURL>
  <
SiteURL> http://serverName.com/Finance/Finance/</SiteURL>
</RemoveMySiteHostURL>

RemoveMySiteHostURL.ps1

## -------------------------------------------------------------------
## Powershell script to remove My Site Host URL
## Note     : Need to update the XML file path before running the script.
## Author         : Vijai Anand Ramalingam
## Date            : 28-Oct-2011
## -------------------------------------------------------------------

#----------------Get the xml file---------------------------------------------------------------

[xml]$xmlData=Get-Content "D:\VijaiPOC\RemoveMySiteHostURL.xml"     

#----------------Remove My Site Host URL function----------------------------------------------------

            function RemoveMySiteHostURL()
            {                      

            $site = Get-SPSite $xmlData.RemoveMySiteHostURL.SiteURL

            ## Get the context of the service application
            $context = Get-SPServiceContext($site)

            $upm = New-Object -TypeName Microsoft.Office.Server.UserProfiles.UserProfileManager -ArgumentList $context
                        $upm.MySiteHostURL="";
                                   
    }

#----------------Calling the function------------------------------------------------------------

RemoveMySiteHostURL

Run the Script:

  1. Go to Start.

  2. Click on All Programs.

  3. Click on Microsoft SharePoint 2010 Products and then click on SharePoint 2010 Management Shell (run as Administrator).

  4. Run the D:\VijaiPOC\RemoveMySiteHostURL.ps1

Thus in this article you have seen how to remove My Site Host URL in SharePoint 2010 using Powershell and SharePoint object model