我在尝试使用 powershell 在 sharepoint 2013 站点上快速启动时更新链接 url 时遇到问题。基本上我只想更改特定链接的 url。我的 Powershell 脚本代码如下:
function FixUrlDocumentsLists() {
param([Microsoft.SharePoint.SPWeb]$SiteIdentity)
if ($SiteIdentity.Url -Like "http://mktintranet/sites/tmmkto/ITReports")
{
$quicklaunch = $SiteIdentity.Navigation.QuickLaunch
if($quicklaunch.Count -gt 0)
{
foreach($node in $quicklaunch)
{
if ($node.Title.ToUpper() -ne "HOME" -and $node.Title.ToUpper() -ne "SITE CONTENTS")
{
if($node.Url -eq $SiteIdentity.ServerRelativeUrl)
{
Write-Host "Fixing navigation links for web $($SiteIdentity.Title)" -ForegroundColor Yellow
Write-Host "Link Title: $($node.Title), OLD Link Url: $($node.Url)" -ForegroundColor Yellow
$node.Url=$node.Url.ToString()+"/_layouts/15/viewlsts.aspx"
Write-Host "Link Title: $($node.Title), NEW Link Url: $($node.Url)" -ForegroundColor Yellow
$node.Update()
$SiteIdentity.Update()
}
}
}
}
}
if($SiteIdentity.Webs.Count -gt 0)
{
foreach($subWeb in $SiteIdentity.Webs)
{
FixUrlDocumentsLists -SiteIdentity $subWeb
}
}
}
错误发生在 $node.Update() 方法上。错误描述如下:
Exception calling "Update" with "0" argument(s): "Cannot open "/sites/tmmkto/ITReports/_layouts/15/viewlsts.aspx": no such file or folder."
我不明白为什么 Update 方法会进行 Url 验证。即使路径 /sites/tmmkto/ITReports/_layouts/15/viewlsts.aspx 确实存在。
谢谢,
马丁