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:

image

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

image

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 = “https://contoso.sharepoint.com/sites/8884aced
$newsiteurl = “https://contoso.sharepoint.com/sites/PublicTest


$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:

image

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

image

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.

tk

ShortURL: https://www.toddklindt.com/PoshReverseArray

Comments

Delhi Russian Escorts

You will love Russian Escort in Delhi. Russian models will arrive at your location shortly after your booking is confirmed. you'll be able to contact us, and we will arrange your appointment with one amongst the best top Russian models. We also have an independent Russian escort in Delhi that provides 24×7 erotic services.
<a href="https://gurugramescort.com/">Gurugram Escort</a>
<a href="https://gurugramescort.com/russian-escort-in-delhi">Delhi Russian Escorts</a>
<a href="https://gurugramescort.com/independent-escort-in-delhi">Independent Delhi Escorts</a>
<a href="https://gurugramescort.com/vip-escorts-in-delhi">Vip Escort In Delhi</a>
<a href="https://gurugramescort.com/near-me/gurgaon-escorts">Gurgaon Escorts</a>
 on 1/5/2022 2:15 AM

Delhi Russian Escorts

You will love Russian Escort in Delhi. Russian models will arrive at your location shortly after your booking is confirmed. you'll be able to contact us, and we will arrange your appointment with one amongst the best top Russian models. We also have an independent Russian escort in Delhi that provides 24×7 erotic services.
<a href="https://gurugramescort.com/">Gurugram Escort</a>
<a href="https://gurugramescort.com/russian-escort-in-delhi">Delhi Russian Escorts</a>
<a href="https://gurugramescort.com/independent-escort-in-delhi">Independent Delhi Escorts</a>
<a href="https://gurugramescort.com/vip-escorts-in-delhi">Vip Escort In Delhi</a>
<a href="https://gurugramescort.com/near-me/gurgaon-escorts">Gurgaon Escorts</a>
 on 1/5/2022 2:16 AM

Запись N21 -  Как Накачать Паховые Мышцы

Wow, awesome blog layout! How long have you been blogging for?
you make blogging look easy. The overall look of your site is
magnificent, let alone the content!
мускулистый бодибилдер homepage мышцы двуглавой мышцы
 on 1/7/2022 6:51 AM

Jaipur Escort

The Pink City of Jaipur is famous all over India for its romantic pink hue, a present from the British from back when the city was painted pink to welcome Prince Albert.  
for more info visit here :- https://escortservicejaipur.com/
 on 1/8/2022 11:16 AM

Anchal kapoor from jaipur escorts

Thanks for sharing such a useful blog,  This is a really smartly written. I need you and you need me…. My name is Anchal kapoor and you can hire me from Jaipur Escorts.
Visit my website: https://anchalkapoor.com/
 
Partner site links: https://www.preetshetty.com/
https://www.manvikakkar.com/
https://www.anusaxena.com/
https://www.delhiescorts.club/
https://www.kiranbajaj.com/
https://www.shreyasehgal.in/
https://www.ashnaimittal.com/
https://www.shwetamahajan.com/
https://www.lavanyakaur.com/
https://www.poonamdas.com/
https://www.preetkaur.com/
https://www.komalshetty.com/
https://www.harmitkaur.com/
https://www.diljotkaur.com/
https://www.shreyasehgal.com/
https://www.ayeshakaur.com/
https://www.parmilajha.com/
https://www.anchalkapoor.com/
https://www.delhicallgirls.club/
https://www.lovelyrani.com/
https://www.malaikaroy.com/
https://www.lovepreet-kaur.com/
https://www.poojarathore.com/
https://www.monika-tiwari.com/
https://www.poonamgupta.com/
https://www.drisina.com/
https://www.russianescortsindelhi.com/
https://www.divyaangi.com/
https://www.shiplichawla.com/
https://www.nirgun.in/
https://www.kimkaur.com/
https://www.namritakaur.com/
https://www.harshitakaur.com/
https://www.mahima-singh.com/
https://www.eashwari.com/
https://www.renubansal.in/
https://www.sonaidas.com/
https://www.alishajain.com/
https://www.dritikaur.com/
https://www.madhavipatel.com/
https://www.jasminder.com/
https://www.lovelyrani.in/
https://www.shilpichawla.com/
https://www.kavitabatra.com/
https://www.komal-gupta.com/
https://www.sujataarora.com/
https://www.priyankaagarwal.com/
https://www.nishaa.in/
https://www.lovelykaur.com/
https://www.amarleen.com/
https://www.dilkaur.com/
https://www.navleenkaur.com/
https://www.deepalimehra.com/
https://www.dhavni.com/
https://www.nidhidixit.com/
https://www.mumbaifemalemassage.com/
https://www.massagecenterinmumbai.com/
https://www.massagecenterindelhi.com/
https://www.delhimassageservice.com/
https://www.delhinightmassage.com/


 on 1/11/2022 1:57 AM

Jaipur Escort

A hostess is somebody you pay to accompany you to a social event. Usually reserved for professional events like business gatherings, company celebrations, or even company parties, these beautiful ladies will go above and beyond to please you.  <a href="https://escortservicejaipur.com/">Escorts in jaipur</a> 
 on 1/11/2022 11:17 AM

Using both PnP PowerShell Modules with PowerShell 5 and PowerShell 7.

 on 1/12/2022 3:59 AM

Jaipur Escort

So it’s the night of the big company party. Everybody’s showing up with their wives and girlfriends in adorable clothes. Nobody wants to show up alone to these events, pointing out their lack of a significant other, which is why getting an escort in Jaipur might be your best idea.

for more info visit here :- https://escortservicejaipur.com/
 on 1/18/2022 9:55 AM

ALINA

Want to visit the famous church in Pakistan? How about visiting the church with a partner? Get a partner from our sexy Pakistan escort agency and enjoy your time with the sexy call girl. Once you see the place, you can take her to your bedroom and have sex with the call girl in Pakistan.
https://pakistanfemales.com/
 on 1/19/2022 6:14 AM

UZMA

These Pakistan escorts are great in bed. They know how to give a body-to-body massage to their special clients. Want to become a special client of our sexy Pakistan escorts? Call us now and get the best rates for nights with escorts.
https://lahorenightlife.com/
 on 1/19/2022 6:15 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.

Title


Body *


Today's date *

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

Twitter


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

Attachments

 

 SysKit