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

Massage Center In Lahore

We Provide The Best Massage Center In Lahore. There Are Full Body Massage And Hot Body Massage Services In Lahore.
https://lahoremassage.co/
 on 8/4/2022 5:39 AM

Karachi Call Girls

Karachi has a multicultural society, and wealthy men are frequently intrigued by the business of attractive women. If you're new and unsure of how to satisfy yourself and your lover, Karachi's call girls can show you how to do it. They are unrestricted by your unreasonable expectations, possess a plethora of skills and experience, and may offer the finest solution for your needs. It provides Karachi's best female escorts! One advantage of using Karachi call girl services is that you won't feel worn out or ignored after doing so. All you need to know is that wherever you are, female escorts make wonderful companions and entertainment. In any case, our escort females make sure to provide the highest quality service at all times.
https://karachicelebrities.com/
 on 8/5/2022 5:05 AM

Escorts in Lahore

There is a lengthy list of call ladies who appear on various websites when it comes to hiring escorts in Karachi. There is everything with cheap escorts in Karachi that you want most to satisfy your wants and demands, whether it's a dinner date or a sensuous service. Selecting a Karachi escort ensures that you will receive all the advantages you desire from any call girl in Karachi. Our female escorts devote their time to our clients and work hard to make them happy in a variety of ways. Always willing to go above and above to win your appreciation, they will.
https://pakistanqueens.com/
 on 8/5/2022 5:05 AM

Escorts in Karachi

We also have a top-notch escorts agency in Karachi. We are happy with all of our stunning call girls in Karachi. We invite you to get in touch with us if you're looking for a close friendship, a dinner date, or any social event with a stunning young girl in Karachi. We thrive at meeting customer needs, and our spas are the best in Karachi.
https://pakistanqueens.com/karachi-escorts/
 on 8/5/2022 5:06 AM

karachi call girls

Escort Karachi are providing the best and top Karachi Call Girls. Our call girls’ rates are lower than other agencies but our staff is very professional. You are a busy person and you do not have to waste time meeting women. The Best Karachi escorts service is a popular girls agency in Karachi. The main purpose is to meet the sexual needs of the customers in such a way that you get a high level of satisfaction from Call Girls. We have a great variety of hot and young Karachi call girls who can satisfy you. You can call Karachi escorts service for booking at any time. 24/7 call girls are available for you in one day.
https://karachimodel.com/call-girls-in-karachi/
 on 8/6/2022 4:19 AM

call girls in lahore

Many people are not satisfied on the escort service in Lahore. Why so? The main reason behind this issue is go with non reputed Escorts Agency In Lahore. Escort industry is huge and here you can find many fake agencies. Most of them provide worst services and gives fake promises to the client. So it’s always better to do some research on agencies before hiring any escort agency.A good and reputed agency will never cheat their customer. Our company always focuses on providing extraordinary services and facilities to our customers. We have professional and mature girls in Lahore who can make your night special and memorable.
https://pakistanfemales.com/call-girls-in-lahore/
 on 8/6/2022 4:19 AM

body massage near me

We offer relaxation and healing services with proven treatments provided by certified professionals in a space that is tranquil, where the your senses are energized, the body is relaxed, and the mind elevated to a feeling of peace. https://www.brightespa.com/
 on 8/8/2022 2:46 AM

body massage near me

Therapist with her hands or fingers , will be able to exaggerate your body, particularly the shank and shoulder as the strain and fatigue is absorbed into these potions in our bodies. She will move your muscles and bones in order to bring you a sense of relaxation. https://www.lishabodyspa.com
 on 8/9/2022 2:33 AM

Karachi Escorts

Services for Karachi Escorts We are aware that the demands and desires of our clientele are diverse. watching many escorts just like this. We also promise that you will locate someone you generally require. Above all, we will encircle you.
https://karachicelebrities.com/
 on 8/10/2022 12:08 AM

Islamabad Escorts

They always offer their clients unique and knowledgeable support. Your interests, emotions, and sexual urges will be actively pursued by them. We have a website, just like the many other providers. Escorts provided by experts We are Islamabad's best professional escorts and can talk about your interests, especially your sexual requirements. Before choosing a certain person, it is imperative that you read the evaluations to understand the kinds of practices they offer. We don't need to talk about prices because they are reasonable with us.
https://islamabadtiktokstars.com/
 on 8/10/2022 12:09 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