2012-05-11 38 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

相關問題