1

I am trying to create a site in SharePoint 2016 using export-spweb import-spweb through Powershell. Everything is working fine except the URLs of Item in Left Navigation\Quick launch.

The issue is especially with the URL\link of 'View all site content' which points to Site Content page of the site. It still points to the 'Site Content' page of the old site instead of the new one that I created through import.

For e.g

I exported the site: ~sitecollection/sitenameA/

Import the site at : ~sitecollection/sitenameB

But the "View All Site Content" in Quick Launch of sitenameB site still point to ~sitecollection/sitenameA/_layouts/15/viewlsts.aspx

Why is it point to old site instead of new one? What is the solution to fix the URL

1 Answer 1

0

The following scripts will provide the ability for exporting the Quick Launch navigation items from one site and import them into another site.

#Get Web and Quick Launch objects
$web = Get-SPWeb http://portal/sites/foundation
$qlNav = $web.Navigation.QuickLaunch

#Create Export File
$xmlFilePath = "C:\Install\QuickLaunchNav.xml"
New-Item $xmlFilePath -type file -force

#Export Quick Launch Navigation to XML file
Add-Content $xmlFilePath "<?xml version=`"1.0`" encoding=`"utf-8`"?>"
Add-Content $xmlFilePath "`n<Navigation>"
$webUrlXml = "`n<WebUrl>" + $web.ServerRelativeUrl + "</WebUrl>"
Add-Content $xmlFilePath $WebUrlXml
Add-Content $xmlFilePath "`n<Headings>"
$qlNav | ForEach-Object {
    $headingXML = "`n<Heading Title=`"" + $_.Title.Replace("&","&amp;") + "`" Url=`"" + $_.Url.Replace("&","&amp;") + "`">"
    Add-Content $xmlFilePath $headingXML
    $_.Children | ForEach-Object {
        $navLinkXML = "<NavLink Title=`"" + $_.Title.Replace("&","&amp;") + "`" Url=`"" + $_.Url.Replace("&","&amp;") + "`"/>"
        Add-Content $xmlFilePath $navLinkXML
    }
    Add-Content $xmlFilePath "`n</Heading>"
}
Add-Content $xmlFilePath "`n</Headings>"
Add-Content $xmlFilePath "`n</Navigation>"
$web.Dispose()

The following scripts will provide the ability for importing navigation items into other sites with replacing the site path

#Get Web and Quick Launch objects
$web = Get-SPWeb http://portal/sites/newsite
$qlNav = $web.Navigation.QuickLaunch

#Get XML File
$xmlFilePath = "C:\Install\QuickLaunchNav.xml"
$xmlFile = [xml](Get-Content($xmlFilePath))
$oldWebUrl = $xmlFile.Navigation.WebUrl
$currentLinks = @()

#Clear Quick Launch links
$qlNav | ForEach-Object {
    $currentLinks = $currentLinks + $_.Id
}
$currentLinks | ForEach-Object {
    $currentNode = $web.Navigation.GetNodeById($_)
    write-host "Deleting" $currentNode.Title "and all child navigation links..."
    $qlNav.Delete($currentNode)
}

#Create Quick Launch Links
$xmlFile.Navigation.Headings.Heading | ForEach-Object {
    $headingNode = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode($_.Title, $_.Url.Replace($oldWebUrl, $web.ServerRelativeUrl))
    write-host "Creating Heading:" $_.Title
    $heading = $qlNav.AddAsLast($headingNode)
    $_.NavLink | ForEach-Object {
        $linkNode = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode($_.Title, $_.Url.Replace($oldWebUrl, $web.ServerRelativeUrl))
        write-host "Creating Navigation Link:" $_.Title
        $link = $heading.Children.AddAsLast($linkNode)
    }
}
$web.Dispose()

Credit: Managing Quick Launch navigation in SharePoint using PowerShell

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.