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("&","&") + "`" Url=`"" + $_.Url.Replace("&","&") + "`">"
Add-Content $xmlFilePath $headingXML
$_.Children | ForEach-Object {
$navLinkXML = "<NavLink Title=`"" + $_.Title.Replace("&","&") + "`" Url=`"" + $_.Url.Replace("&","&") + "`"/>"
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