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.

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