2012-05-11 125 views
1

我想使用PowerShell将QuickLaunch链接添加到网站。在SharePoint网站上添加新的quicklaunch导航链接

我目前使用的脚本是:

$web = Get-SPWeb http://sp_3/Deps 
$node = New-Object -TypeName Microsoft.SharePoint.Navigation.SPNavigationNode 
    -ArgumentList "LinkTitle", "http://sp_3/Deps/SUP" 
$web.Navigation.QuickLaunch.Add($node); 
$web.Update() 

这将导致以下错误:

Can not find an overload for the "Add" and the number of arguments: "1." line: 1 char: 32 
    + $ Web.Navigation.QuickLaunch.Add <<<< ($ node); 
    + CategoryInfo: NotSpecified: (:) [], MethodException 
    + FullyQualifiedErrorId: MethodCountCouldNotFindBest 

我在做什么错?

回答

1

方法SPNavigationNodeCollection.Add需要第二个参数 - 现有的SPNavigationNode将新添加的一个放在它后面。例如,您可以找到一个by URL,或者通过枚举集合。或者将您的新产品放在前面(AddAsFirst)或后面(AddAsLast)。

$web.Navigation.QuickLaunch.AddAsLast($node) 

更新:如何将链接添加到站点组:

$quickLaunch = $web.Navigation.QuickLaunch 
# Print the $quickLaunch collection and choose a property 
# identifying the best the link group you want. I chose URL. 
$sitesUrl = "/sites/team/_layouts/viewlsts.aspx" 
$sitesGroup = $quickLaunch | Where-Object { $_.Url -eq $sitesUrl } 
$sitesGroup.Children.AddAsLast($node) 

--- Ferda

+0

好的)谢谢! '$ web = Get-SPWeb http:// sp_3/Deps $ node = New-Object -TypeName Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList“LinkTitle”,“http:// sp_3/Deps/SUP”,1 $ web.Navigation.QuickLaunch.Add($节点); '使用此代码我得到一个胖链接到您的网站。 (现在我的链接位于快速启动栏上,很孤独) 问:我如何让标题为Sites的链接? – spbsmile

+0

我希望你能理解我 – spbsmile

+0

网站同时是一个链接和一个链接组。请参阅我的回答中的更新如何向其添加子链接。 –

2

啊! This page有最优秀的教程和例子。这是我工作的东西(SP 2010)

$quickLaunch = $currentWeb.navigation.quicklaunch 
$libheading = $quickLaunch | where { $_.Title -eq "Libraries" } 
$newnode = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode($whattitle, $myurllink, $true) 
$libheading.Children.AddAsLast($newnode) 
$currentweb.update() 
+1

使用SharePoint 2013创建指向文档库的节点时,会出现以下警告:如上所述添加节点无法创建启用** drop的**链接。因此,对于这种情况,请设置list.OnQuickLaunch属性以获取自动创建的节点。 –

+0

感谢那里的其他人的指针。我自己仍然卡在2010年。 +1 – bgmCoder

相关问题