Create Lists and modify navigation using Powershell

24 May 2011 4:44 AM Posted by Mano Mangaldas

Create Lists and modify navigation using Powershell


The below code creates a new discussion board in every immediate subsite of the site url provided. It also adds a QuickLaunch link to the discussion board created.

$SPSite = New-Object Microsoft.SharePoint.SPSite("http://localhost:1000/sites/demo"); 
$ParentWeb = $SpSite.OpenWeb(); 

$ChildWebs = $ParentWeb.Webs;
foreach($web in $ChildWebs)
{
      $TemplateType = $web.ListTemplates["Discussion Board"]; 
      #$web.Lists["Discussion Board"].Delete();

      $web.Lists.Add("Discussion Board","Discussion Board",$TemplateType); 
      $newList =  $web.Lists["Discussion Board"];

      $nodes = $web.Navigation.QuickLaunch;
      foreach($node in $nodes)
      {
            if($node.Title -eq "Lists")
            {
                  $navNode = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode("Discussion Board", $newList.get_DefaultViewUrl(), $true);
                  $node.Children.AddAsLast($navNode);
            }
      }
      $web.Dispose(); 
}
$ParentWeb.Dispose();
$SPSite.Dispose();

Comments (0)

Post a Comment