Copy/Export Navigation?

Bronze Contributor

Is there a PowerShell command (or other way) to export a hub site navigation and import it to another hub site navigation?

18 Replies
Take a look at PnP cmdlets, you might find there what you need

hi @Jens Balondo 

 

Thanks, but how do I provide credentials to this module?

I've opened the SharePoint Online Module and logged in, than imported the module and ran the command from the scripts comments, but I always get the information pop to provide credentials but at no point do I get to enter any credentials.

 

*edit*

I've managed to get the script to run, but I can't produce any changes to my navigation unfortunately. No Idea why.

 

@jcgonzalezmartinthanks for your input. My PowerShell skills are limited to basic administration and some modifying of existing scripts. I can get the navigation links but I have no idea how to export or copy those 😞

Is it possible, that the Add-PnPNavigationNode command has not been updated yet to the new mega menu options, like a header that isn't a link?
I can't get this work 😞

@Jens Balondo Is this script works for Mega Menu as well?

As I tried and it only copied the first level of navigation, not copied sub-navigation items.

@Ivan Unger Any updates on this?  I have a similar requirement and we're using megamenu three deep.

 

Cheers!

@Ivan Unger and @MoTheSeeker - I found a script that works with mega menu!  I ran the script from SharePoint Online Management Shell.  Here is the link containing the script: 

 

https://jcallaghan.com/2019/09/replicate-sharepoint-hub-site-navigation/

 

However, it was only copying non-hyperlinked headings.  So I had to add an "-external" switch to get any hyperlinked menu items to copy.  This is noted in the article above but better detailed in this second article below:

 

https://davegerrard.wordpress.com/2019/12/05/editing-hub-site-navigation/

@Ivan Unger 

Hi Ivan, 

You can use the Copy-PNPNavigation module 
You can copy a SharePoint Navigation Menu with maximum 3-layer with this script. Also, you will have a export in excel type from the site navigation!

 

https://www.powershellgallery.com/packages/Copy-PNPNavigation/1.0.2

@Saeid_Abdollahzadeh I just ran this module and got the following message "Backup process is done, you can find the back up file in the destination folder"  and "You skip the restore process".   Currently, I cannot find the backup excel file and the navigation in the destination site was not changed.  Any idea what I'm missing here?  Thanks

Hi @Darren_Smith 

 

Copy-PNPNavigation -SourceSite https://contoso.sharepoint.com/sites/SourceSite -BackupDestination C:\FolderOfBackupFile -DestinationSite https://contoso.sharepoint.com/sites/DestinationSite -NavigationLocation TopNavigationBar

 

It's the full line of the command. You have to enter the source site address, which you want to copy the navigation from it, then you need to enter the destination folder where the backup file will save there. If you're going to add the navigation menu to the destination site, you have to use the -DestinationSite switch, otherwise the backup file doesn't copy to the destination site, and you have the backup file only!

https://github.com/saeid-adz/Copy-PNPNavigation

 

BR,

Saeid.

@Saeid_Abdollahzadeh Hi Saeid, thanks so much for your reply and the clarification.  When running the command, I now get an error 'D:\SiteNavigationBackup.xlsx' file not found.  When viewing the directory, the backup file was never written.  Am I missing something?  

@Saeid_Abdollahzadeh also, just to clarify, I'm running Powershell as an admin

Hi again @Darren_Smith 

I suggested that you use a specific folder instead of the drive path for the backup file! for example:

 

Copy-PNPNavigation -SourceSite https://YourSourceSite.sharepoint.com -BackupDestination C:\Backup -DestinationSite https://YourDestinationSite.sharepoint.com/sites/TEST -NavigationLocation TopNavigationBar

 

You will see the "SiteNavigationBackup.xlsx" in the Backup folder!

It should be fixed by this command!

Also, make sure that you use version 1.0.2

 

good luck 🙂

 

BR,

Saeid.

@Saeid_Abdollahzadeh 

So mine did not turn out as expected at all...there's duplicates everywhere.  What do I do? 

spo.PNG

@AlexanderSalamander getting duplicates. Any solutions? 

@Martien1030 @AlexanderSalamander
Im also getting such duplicates. Any updates / solutions?

@Saeid_Abdollahzadeh - I just tried your module after making a couple modifications and it worked great.  Updated changes needed where:

  • Replace -UseWebLogin with -Interactive  (so it supports MFA login)
  • Replace SharePointPnPPowerShellOnline with PnP.Powershell

I'm new to Github, so not sure if i did this right, but made the corrections in fork at 
Comparing saeid-adz:master...robert-studio365:patch-1 · saeid-adz/Copy-PNPNavigation (github.com)

Also took me awhile to figure this out, but using "-NavigationLocation QuickLaunch" instead of "-NavigationLocation TopNavigationBar" also worked great with this module.  

Thanks for sharing.  

@Saeid_Abdollahzadeh - one correction.  The first half of the script that copies all the QuickLaunch nav menus to an excel works perfectly.  After that there are two problems: 

  1. It doesn't seem to be copying the MenuURL to the target site.  And even if it didn't error out, in the spreadsheet the URL is being saved as "sites/SOURCESITE/Sitepages...".   Possible to modify the script so that when writing to the new site it updates that relative reference? 
  2. It's generating an error of "Add-PnPNavigationNode: Object reference not set to an instance of an object.".  

If you have a chance to update this, that would be greatly appreciated.  Thank you.