Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Monday, November 28, 2011

Create Lists and modify navigation using Powershell

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();

No comments:

Post a Comment