power shell script may be wrong

Oct 27, 2009 at 4:24 PM

Hi there,

I've downloaded your tool, and it works very well, except the powershell script is not created as expected.

[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");

$url = "http://sharepointdev"
$topsite = new-object Microsoft.SharePoint.SPSite $url;
$topweb = $topsite.OpenWeb()
$topnavs = $topweb.Navigation.TopNavigationBar

$node0 = $topnavs[0]
while ($node0.Children.Count -gt 0) { $node0.Children.Delete($node0.Children[0])}

$node1 = new-object Microsoft.SharePoint.Navigation.SPNavigationNode -argumentlist @("Home", "/", $False)
$node1 = $node0.Children.AddAsLast($node1)
$node1 = new-object Microsoft.SharePoint.Navigation.SPNavigationNode -argumentlist @("Human Resources", "/sites/HR", $False)
$node1 = $node0.Children.AddAsLast($node1)
$node1 = new-object Microsoft.SharePoint.Navigation.SPNavigationNode -argumentlist @("Projects", "/sites/Projects", $False)
$node1 = $node0.Children.AddAsLast($node1)


After i've run the above script on the sharepoint server, it returned some errors. After some digging in the MSDN for the SPNavigationNode and SPNavigationNodesCollection classes, I modified the script to look like this:

[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");

$url = "http://sharepointdev/"
$topsite = new-object Microsoft.SharePoint.SPSite $url;
$topweb = $topsite.OpenWeb()
$topnavs = $topweb.Navigation.TopNavigationBar

while ($topnavs.Count -gt 0) { $topnavs.Delete($topnavs[0])}

$node1 = new-object Microsoft.SharePoint.Navigation.SPNavigationNode -argumentlist @("Home", "/", $False)
$node1 = $topnavs.AddAsLast($node1)
$node2 = new-object Microsoft.SharePoint.Navigation.SPNavigationNode -argumentlist @("Human Resources", "/sites/HR", $False)
$node2 = $topnavs.AddAsLast($node2)
$node3 = new-object Microsoft.SharePoint.Navigation.SPNavigationNode -argumentlist @("Projects", "/sites/Projects", $False)
$node3 = $topnavs.AddAsLast($node3)

All I wanted is to make a simple top navigation that contained only 3 nodes.

When you have some time, you can look why this has happened.

 

Regards,

Voicu Seiche.