Provisioning My Sites SharePoint 2010

In certain scenarios you would like to provision the My Sites of the users before you go live with the environment. Within SharePoint 2010 you have got several options to complete this task.

One of the options is to create a PowerShell script. With PowerShell you have the ability to read through the user profile store that is used for a certain web application and create a My Site for each profile in the profile store. If you want to use PowerShell to accomplish this task you can use the following script:

$siteurl = "http://yoursiteurl"     
$site = New-Object Microsoft.SharePoint.SPSite($siteurl) 
$context = [Microsoft.Office.Server.ServerContext]::GetContext($site) 
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context) 

$profiles = $upm.GetEnumerator()
foreach ($userobject in $Profiles ) {

    # start loop here 
    $user = $userobject.item("AccountName")
    if ($upm.UserExists($user)) { 
        $profile = $upm.GetUserProfile([string]$user) 
        # there are other exceptions you can catch, check out the UserProfiles class 
        trap [Microsoft.Office.Server.UserProfiles.PersonalSiteExistsException] { 
            Write-Host "personal site already exists for $user" 
        trap {
        Write-Host "Error creating site for $user" -ForeGroundColor Red
        Write-Host "Personal site for $user created..." -ForeGroundColor Green
    }  else { 
      Write-Host: "user $user did not exist" 
# end loop here 

The second option you have is creating a C# application. This c# application will to exactly the same as the powershell script. The method to create the MySites is displayed below.

private static void CreateMysite(string siteUrl)
            using (SPSite site = new SPSite(p_2))
                SPServiceContext serviceContext = SPServiceContext.GetContext(site.WebApplication.ServiceApplicationProxyGroup, SPSiteSubscriptionIdentifier.Default);
                UserProfileManager profileConfigManager = new UserProfileManager(serviceContext);
                    long count = profileConfigManager.Count;

                    for (int i = 1; i <= count; i++)
                            UserProfile profile = profileConfigManager.GetUserProfile(i);
                catch (UserNotFoundException) {}

In the application above I catch the UserNotFoundException this is done because it can occur that a user profile is present but not the user.

Related Posts

Active Directory Picture Synchronization When you have stored the pictures of employees in Active Directory you would like to have the option to synchronize these pictures to their SharePoint...
Deleting a Project Service Application within SharePoint 2010 A couple of days ago I deleted my Project Server Web application because I wanted to recreate it. When I tried to create a new Project Web App ...
Deleting the extended web application This post I’m as a reminder because a few days back when I was working on a production environment for one of our clients. I had created an extend...
Office 2010 and SharePoint 2010 Service Pack 1 Two days ago Microsoft released the first Service Pack for the 2010 Office suite. This means there is also a Service Pack for SharePoint 2010. ...
SharePoint 2010 Content Organizer Feature Within SharePoint 2010 Microsoft has changed a lot of the content management features. One of those features is content routing which you can do with...
Creating Metadata Properties through code – SharePoint 2010 When you work on SharePoint project you often see solutions that are built by using the search engine of SharePoint. To perform queries against the s...


  1. Thanks for this post. I posted a question in the SharePoint Admin forum how to do this and someone pointed me to this post of yours.

  2. Hi,

    I’m no developer so forgive the lack of detail. I’ve run this powershell script but receive the following error for every user.

    Error creating site for appex\SHunteering
    Personal site for appex\SHunteering created…

    While the output states the personal site was created, it wasn’t.

    Any suggestions?

    Many thanks,


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.