Skip Ribbon Commands
Skip to main content

Quick Launch

Todd Klindt's home page > Todd Klindt's Office 365 Admin Blog > Posts > Reversing Arrays easily in PowerShell
October 31
Reversing Arrays easily in PowerShell

I was recently dealt a fun task from a customer. They had a site in SharePoint that had a few links in the Quick Launch (left nav, quick nav, whatever) and they wanted to copy the Quick Launch from another site to it. They wanted to keep the existing links below the new ones. Here are some pictures to help it all make sense:

I want to copy these links:


and put them on top of these links on another site.


Of course I immediately thought of your friend and mine, the PnP PowerShell for this task. Sure enough, there are cmdlets for that, Get-PnPNavigationNode and Add-PnPNavigationNode. Just what the doctor ordered.

Add-PnPNavigationNode is pretty basic and I had to work a bit to get exactly what the customer wanted. When you add a Navigtation node with Add-PnPNavigationNode it puts it at the end of the list, which makes sense. You can also throw the switch parameter, –First, to put it at the top. In most situations that probably is fine, but mine was tricky. I didn’t want to put the copied nav nodes at the end, I wanted the existing ones to stay there. I also couldn’t just add them all as –First because then they would end up at the top, but in backwards order. When I get the old nav nodes with Get-PnPNavigationNode it returns them in their correct order, so as I walked through them with Foreach the first one would be added on top, but then the second one, also with the –First switch, would end up on top, and so on. Enter [array]::Reverse.

The Array class in PowerShell has quite a few tricks up its sleeve in the form of operations, and Reverse is one of them. If you want to see the rest, go to this page, or type [array]:: in a PowerShell host and tab through the list. It’s quite impressive. 

Here’s what my code looked like:

$oldsiteurl = “
$newsiteurl = “

$oldsite = Connect-PnPOnline -Url $oldsiteurl -Credentials Compliance -ReturnConnection
$newsite = Connect-PnPOnline -Url $newsiteurl -Credentials Compliance –ReturnConnection

$oldnavlinks = Get-PnPNavigationNode -Location QuickLaunch -Connection $oldsite

[array]::Reverse($oldnavlinks) # <-- The magic goes here

foreach ($link in $oldnavlinks) {
Add-PnPNavigationNode -Location QuickLaunch -Title $link.Title -Url $link.Url -First -Connection $newsite -External

There’s a lot of foundation there, but you can see where the Array reversal fits in. Here’s how it looked when I ran it:


And here’s what it looked like after I ran it:


There’s a lot more tweaking I can do, like make sure “Home” is still on top, stuff like that, but finding Reverse was an important step in the beginning.




Home Cleaning Services in Noida
 on 2/17/2023 6:57 AM

Cricket Live | Skowpedia
 on 2/18/2023 1:56 AM


I have been looking for articles on these topics for a long time.
 I don't know how grateful you are for posting on this topic. Thank you for the numerous articles on this site, I will subscribe to those links in my bookmarks and visit them often. Have a nice day.
 on 2/19/2023 10:30 PM

escorts in Karachi

Pakistan Call girls are different from Just share what you want with them and They will serve you with unique and unforgettable happiness without compromise. So don’t worry if you are a beginner, and our young  girls will command you in Karachi.
 on 2/20/2023 2:27 AM


JAKARTA, Feb 7 (Reuters) - Separ<a href="">다이아출장샵</a>atist fighters in
 on 2/21/2023 12:45 AM

Call girls in Lahore | 03001191915 | Escorts in Lahore providing services of Call Girls Booking in Lahore For Party Dance Night Booking and any ceremonies,
<a href="">ESCORTS IN LAHORE</a>
 on 2/21/2023 12:55 AM


Some phenomenal considering calories tips are exhibited by the going with: Eat stores of ordinary things, vegetables and entire grains. Endeavor to limit your salt affirmation. Eliminate a piece of the salt you use with new flavors. Keep away from high-fat dairy things.To know more visit us :

 on 2/21/2023 1:14 AM

Marriage registration noida

In today’s era, finding your ideal companion is easier than you believe. So, give marital websites a shot if you’re looking for a committed relationship.We are a group of lawyers that provide sincere assistance with marriage registration in Noida, marriage registration in the city, and property registration in Noida.
<a href=>Marriage registration noida</a>
 on 2/21/2023 2:24 AM

Best Home Cleaning Services in Noida

 on 2/21/2023 4:02 AM

Cricket Live | Skowpedia

 on 2/22/2023 1:45 AM
1 - 10Next

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.


Body *

Today's date *

Select a date from the calendar.
Please enter today's date so I know you are a real person


Want a message when I reply to your comment? Put your Twitter handle here.