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

Psychology Writing Services Online

Obtaining Psychology Writing Services is fulfilling for most students who have to struggle with deadlines on Psychology Coursework Writing Services and Psychology Homework Writing Services.
https://www.meldaresearch.com/psychology-writing-service/
 on 1/22/2020 2:46 AM

Get MS Office 365 Download Frequently Via Helpline Number

MS Office suite contains numerous programs such as MS Word, Excel, PPT, Outlook and many more through which users can create, edit content or manage their work-report in handy way. But for availing all its applications as well as features, you need to get MS Office 365 Download first in your PC. If you don’t know the actual downloading procedure, don’t feel bad! As we have tech-savvy who consistently been present at toll-free number for your aid. So, stop being worrying anymore and place an instant call on the 24/7 accessible contact number to reach them sooner and get one-stop solution.
Visit here:- https://www.office365download.co/
 on 1/23/2020 4:40 AM

Is there a phone number for Outlook support?

The mentioned points in this guide are very informative and helped me to resolve my issue in a very proficient manner. At the time of solving my query I got stuck at one point, so I called at Outlook Support Phone Number and the technician who answered my call guided me thoroughly to get rid of my issue. I really appreciate the hardworking of that guy, who helped me during my crisis of time and never leave my side until problem didn’t get resolved. Therefore, I personally suggest everyone to get hold of Microsoft Outlook Support if you really want to resolve your query related to your Outlook comparison to solve problems on your own.  
Website:-  https://www.microsoftoutlooksupportnumber.com/ 
https://www.microsoftoutlooksupportnumber.com/microsoft-office-support 
https://www.microsoftoutlooksupportnumber.com/office-365-support 
https://www.microsoftoutlooksupportnumber.com/hotmail-support
https://www.microsoftoutlooksupportnumber.com/windows-support 
 on 1/23/2020 4:53 AM

outlook support phone number

This post is extremely amazing! This blog gives the ideas to take support from Outlook Support Phone Number. This post is helpful for users to obtain Microsoft Outlook Support from trained technicians. Thanks for sharing this post!
Address:- 11877 Douglas Rd, Johns Creek, GA 30005
https://www.outlooksupportphonenumber.co/ 
 on 1/23/2020 4:55 AM

Is there a Phone Number for Office 365 Support?

Incredible blog! The post is extremely helpful for office 365 users to get the details about office 365 Support. The excellent blog is the right place to get ideas about quick Microsoft Office 365 Support. Thanks for sharing this post! Visit here:-
https://www.microsoftoffice365support.co/
https://www.microsoftoffice365support.co/outlook-support 
https://www.microsoftoffice365support.co/microsoft-support 
https://www.microsoftoffice365support.co/blog/fix-outlook-send-and-receive-error/ 
https://www.microsoftoffice365support.co/blog/what-is-microsoft-office-365/ 
https://www.microsoftoffice365support.co/blog/outlook-error-codes-0x80070002/ 

 on 1/23/2020 4:56 AM

Outlook Keeps Asking For Password

While using Microsoft outlook, you can experience the complicated situation that MS outlook keeps asking for a password, which is certainly a working thing. Normally, there are many possible causes behind this error. It may be very difficult situation for Outlook users. Possible causes lead Outlook Keeps Asking for Password error. Our Outlook technicians are technically trained for resolving this issue completely from the root. They have technical skills and proficiency for fixing any type of technical issues related to Outlook. Our helpline number is open 24/7 to provide immediate support or help for any type of technical troubles.
https://www.microsoftoutlookoffice.com/blog/outlook-keeps-asking-for-password/
https://www.microsoftoutlookoffice.com/blog/how-to-convert-from-outlook-working-offline-to-online/ 
https://www.microsoftoutlookoffice.com/blog/how-to-resolve-outlook-error-0x800ccc0e/ 
https://www.microsoftoutlookoffice.com/blog/fix-outlook-error-0x800ccc0f/ 
https://www.microsoftoutlookoffice.com/blog/convert-ost-to-pst-file/
https://www.microsoftoutlookoffice.com/blog/fix-outlook-send-receive-error/ 
https://www.microsoftoutlookoffice.com/blog/fix-outlook-not-responding-error/ 
https://www.microsoftoutlookoffice.com/blog/install-microsoft-office-365/ 
https://www.microsoftoutlookoffice.com/blog/essential-steps-to-recover-deleted-files-windows-10/ 
https://www.microsoftoutlookoffice.com/faq/contact-microsoft-outlook-support 
https://www.microsoftoutlookoffice.com/outlook-customer-service
https://www.microsoftoutlookoffice.com/outlook-help 
https://www.microsoftoutlookoffice.com/microsoft-support-number
https://www.microsoftoutlookoffice.com/office-365-support 
 on 1/23/2020 4:58 AM

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