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.
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:
-
Go to Start.
-
Click on All Programs.
-
Click on Microsoft SharePoint 2010 Products
and then click on SharePoint 2010 Management Shell (run as Administrator).
-
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