1

我想使用 powershell 将 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

我究竟做错了什么?

4

2 回答 2

2

啊! 这个页面有最优秀的教程和例子。这对我有用(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()
于 2012-11-21T23:13:01.200 回答
1

The method SPNavigationNodeCollection.Add needs a second parameter - an existing SPNavigationNode to place the newly added one behind it. You can find one by URL, e.g., or by enumerating the collection. Or just place your new one to the front (AddAsFirst) or to the back (AddAsLast).

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

Update: How to add a link to the Sites group:

$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

于 2012-05-11T06:59:07.967 回答