通过PowerShell更新SharePoint快速启动链接URL

时间:2010-11-25 10:02:28

标签: sharepoint powershell sharepoint-api

设置是MOSS2007。我迭代QuickLaunch中的链接,并更新URL:

$siteUrl = "http://myserver/"
$spSite = new-object Microsoft.SharePoint.SPSite($siteurl) 
for($i=0; $i -lt $spSite.AllWebs.Count;$i++)
{
    $spWeb = $spSite.AllWebs[$i]
    $nodes = $spWeb.Navigation.QuickLaunch
    for($j=0; $j -lt $nodes.Count;$j++)
    {
            $children = $nodes[$j].Children
            for($k=0; $k -lt $children.Count;$k++)
            {
                    $x = $children[$k]
                    $x.Url = "http://mylink/"
                    $x.Update()
            }
    }
    $spSite.Dispose();
}

但Doclib网址不会更新。如果我转到网站设置 - >导航 - >并通过UI编辑URL,然后再次运行我的脚本,URL更新。为什么我不能通过代码操纵URL?

1 个答案:

答案 0 :(得分:1)

我不确定这是不是答案,但在我看来,你的Dispose在错误的地方。它应该在外部foreach之外,即与$ spSite赋值处于相同的嵌套级别。这种重复处理可能会导致同步问题。