I have a problem when trying to update link urls in quick launch on sharepoint 2013 site with powershell. Basically I only want to change the url of specific links. My Powershell script code is as follows:
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
}
}
}
The error occurs on $node.Update() method. The error description is as follows:
Exception calling "Update" with "0" argument(s): "Cannot open "/sites/tmmkto/ITReports/_layouts/15/viewlsts.aspx": no such file or folder."
I can't realize why the Update method is making Url validation. Even though the path /sites/tmmkto/ITReports/_layouts/15/viewlsts.aspx does exists.
Thanks,
Martin
Please ensure Show sub sites/Show pages option is unchecked under
Site Settings =>Navigation => Current Navigation=>
in Navigation: Display only the navigation items below the current site. You will get such error, if you try to update the Navigation links generating from the Sub Site/ Page files. It make sense for giving error if this option in on and you try to modify the link for auto generated sub site/Page link.