Thursday, November 10, 2011

Manual creation of a MySite Site Collection

It just happens that sometimes we need to do something out of the normal process. In this case, I had to manually create a MySite site collection for a user.

Manual creation using UI doesn't give any error message but it doesn't work. Site was created & the structure in place but when I click My Contents (content if for a different user), nothing happens.

So I tried using PowerShell. Below is the code that I used, which was adapted from another blog post.

$mysiteHostUrl = "<your MySite Host URL>"
$mysite = Get-SPSite $mysiteHostUrl
$context = [Microsoft.Office.Server.ServerContext]::GetContext($mysite)
$upm =  New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$AllProfiles = $upm.GetEnumerator()
foreach($profile in $AllProfiles)
{
   if ($profile.DisplayName -like "User Name")
   {    
      if($profile.PersonalSite -eq $Null)
      {
           write-host "Creating personal site for ", $profile.DisplayName
           $profile.CreatePersonalSite()
           write-host "Personal site created"
      }
      else
      {
           write-host $profile.DisplayName ," has already personal site"
      }
   }
}
$mysite.Dispose();

A Few important notes:

1. Initially, when I test this in my dev environment, the line below returned null all the time even though the personal site exist.

$profile.PersonalSite

I guess something is wrong with the User Profile Service (UPS). When I tried the code in another environment, it returned the expected values. So we need to verify first if the our UPS is working fine before attempting to run the code.

2. If line below gives you an error,

$upm =  New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)

give the account you are running the powershell full control in 2 places - see below



Code above was adapted from: http://blog.bugrapostaci.com/2011/10/03/create-all-users-personal-site-via-powershell-script-sharepoint-2010/

2 comments:

  1. Related…...

    [...]just beneath, are numerous totally not related sites to ours, however, they are surely worth going over[...]…...

    ReplyDelete
  2. Sites we Like…...

    [...] Every once in a while we choose blogs that we read. Listed below are the latest sites that we choose [...]…...

    ReplyDelete