How to apply master in Private MySites

Today’s problem is easy to solve once you get the solution 😛

The problem is the following, by Designer is it posible to upload the master for the public MySites, but once the user has created his personal space and he/she enters to the private site (OneDrive, Blog, Tasks,etc…) the master applied in this case is the default master.

To solve this error, we have created a PowerShell that could be added as a scheduled task, and this PS apply a master for all personal sites in the farm.

The only parameter that need to be configured is $masterpageSRC, this variable need the path where the master file is located

# Contenido del invocador del PS del Sharepoint copiado aqui directamente. Inicio
#
$ver = $host | select version
if ($ver.Version.Major -gt 1)  {$Host.Runspace.ThreadOptions = "ReuseThread"}
Add-PsSnapin Microsoft.SharePoint.PowerShell
Set-location $home
#
# Contenido del invocador del PS del Sharepoint copiado aqui directamente. Fin
#
[void][System.reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[void][system.reflection.assembly]::loadwithpartialname("Microsoft.Office.Server.UserProfiles")
#Primeramente se debe de haber creado un sitio en Sharepoint donde se colgarán todas las fotos de usuario
#el nombre de la foto debe de ser el mismo que el nombre de login de usuario
#Es necesario especificar la url de la granja
$personalSites = get-spsite -limit ALL | where {$_.RootWeb.WebTemplate -eq "SPSPERS"}
foreach ($SiteUrl in $personalSites) { 
 write-host "Applying master page to Url", $SiteUrl
   $site=Get-SpSite $SiteUrl
 $web=$site.RootWeb
 $masterPageSrc = "C:XXX.master"
 $masterPageDest = $web.GetFolder("Master Page Gallery")

 Get-ChildItem $masterPageSrc | foreach { 
  $stream = [IO.File]::OpenRead($_.FullName)
  $destUrl = $web.Url + "/_catalogs/masterpage/" + $_.Name.Replace(" ","") 
  $resultingfile = $masterPageDest.files.Add($destUrl, $stream, $true)
  $stream.close()
 } 
 $masterUrl = New-Object System.Uri($destUrl)
 $web.MasterUrl = $masterUrl.AbsolutePath
 $web.CustomMasterUrl = $masterUrl.AbsolutePath
 $web.Update()
 $web.Dispose()
 $site.Dispose() 
   write-host "Done"
}

Hope it helps!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s