Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How To Restore Default Companyweb Homepage in SBS 2011 Standard


Summary

SBS 2011 Standard installs Sharepoint 2010 Foundation.  During the setup process, a default site is created with a specific homepage.  Some custom options are choosen for the webparts on the homepage that are difficult if not impossible to set manually.

↑ Back to the top


More Information

The following script will reset the Companyweb homepage back to the default page that is configured by SBS 2011 Standard Edtion setup.  The script will remove any customizations to the home page.

1.  Open notepad on the server.

2.  Copy the following text and paste it into notepad:

function CreateListViewWebPart($web, $type)
{
 $list = $web.Lists | where {$_.BaseTemplate -eq $type} | select -First 1
 $webPart = new-object Microsoft.SharePoint.WebPartPages.XsltListViewWebPart;
 $webPart.ListName = $list.ID.ToString("B").ToUpper();
 $webPart.ViewGuid = $list.Views[""].ID.ToString("B").ToUpper();
 return $webPart
}

function CreateImageWebPart($web, $link, $text)
{
 $webPart = new-object Microsoft.SharePoint.WebPartPages.ImageWebPart;
 $webPart.ImageLink = $link;
 $webPart.AlternativeText = $text;
 $webPart.ChromeType = 'None';
 return $webPart
}

function GenerateColumn($web, $webPartMgr, $webParts, $width)
{
 $content = '<td style="width:'+$width+'%">';
 $content += "<div>&nbsp</div>";

 $WEB_PART_STRING_FORMAT  = "<div class='ms-rtestate-read ms-rte-wpbox' contentEditable='false'><div class='ms-rtestate-read {0}' id='div_{0}'></div><div style='display:none' id='vid_{0}'/></div>";

 $webparts | foreach {
  $webPartMgr.AddWebPart($_, "wpz", 0);
  $id = $webPartMgr.GetStorageKey($_);
  $content += [System.String]::Format($WEB_PART_STRING_FORMAT, $id.ToString("D"));
 }

 $content += "</td>"

 
 return $content
}

$web = Get-SPWeb "http://companyweb";
$file = $web.GetFile("SitePages/Home.aspx");
$file.CheckOut();
$webPartMgr = $file.GetLimitedWebPartManager('Shared')

[Collections.ArrayList]$webPartMgr.WebParts | %{$webPartmgr.DeleteWebPart($_)}

$content = "";
$content += '<table id="layoutsTable" style="width:100%">';
$content += '<tbody>';
$content += '<tr style="vertical-align:top">';

$announcements = CreateListViewWebPart $web 'Announcements'
$events =  CreateListViewWebPart $web 'Events'
$links  = CreateListViewWebPart $web 'Links'
$logo = CreateImageWebPart $web "/Pictures/Photos/SBS_logo.png" "Windows Small Business Server Logo"

$leftWebParts = $announcements, $events
$rightWebParts = $logo, $links

$content += GenerateColumn $web $webPartMgr $leftWebParts 70
$content += GenerateColumn $web $webPartMgr $rightWebParts 30

$content += "</tr></tbody></table>"

$file.Item["WikiField"] = $content;
$file.Item.Update();
$file.Update();
$file.CheckIn("");


 

3.  Save the file as configurehomepage.ps1

4.  Run SharePoint PowerShell as Administrator

5.  In the SharePoint PowerShell, type .\configurehomepage.ps1

 

↑ Back to the top


Keywords: vkball, kb

↑ Back to the top

Article Info
Article ID : 2539296
Revision : 1
Created on : 1/8/2017
Published on : 3/5/2012
Exists online : False
Views : 89