PowerShell to Embed JavaScript using Site Collection User Custom Action

The script below will insert a JavaScript reference that will be embedded into all pages of your site collection.

Assuming you have a JavaScript file called global.js in the Site Collection’s Site Assets library. Can be parameterised for more customisation.

Continue reading


PowerShell to Insert Field to List View at Specific Location

Added a new field (AddressLine1) to a list, and needed to display the field in all list views. It needed to always display before another field (AddressLine2).

Script below loops through all views of a list, and if the AddressLine2 field exists, it will add AddressLine1 just before it.

Note: Can’t use ForEach loop to go through each list view as the .Update() will throw an error, due to restrictions in updating collection items while enumerating.

Continue reading

Reordering SharePoint Fields using PowerShell

The order in which fields are displayed in the New, Edit, and Display forms for a list item is determined by the FieldLinks order of its content type.


The SPFieldLinkCollection has a handy Reorder method that we can use to set the order of the fields, using their internal names

The script below does this through PowerShell:

Continue reading

Running Content Iterator in PowerShell

PowerShell can be very useful to quickly write up a script when you need to say update a field value for items in a list.

But what happens if your list happens to have 100,000+ items? Doing SPList.Items is going to get throttled.

And while PowerShell doesn’t have an equivalent for the ContentIterator class (which can iterate through large data sets while avoiding throwing a SPQueryThrottledException), we can run custom code through PowerShell that utilizes ContentIterator.

The script below does a simple field update for items of a specific content type in a list.

Continue reading

Updating Managed Navigation Settings for SharePoint Online using PowerShell

Recently we were trying to update our company’s SharePoint Online intranet’s top navigation into displaying as a mega menu. As part of the change, there was also a need to clean up the links currently being displayed to be more usable to the staff users.

Because the current top navigation was using Structural Navigation, and we weren’t prepared to overhaul the entire site structure to accommodate the new navigation’s information architecture, we decided to switch to using Managed Navigation, and use a Navigation term set to define the links.

However, by default, new pages created under Managed Navigation will be added to the navigation automatically, and will be using Friendly URLs. This is set in the Navigation Settings for each site.


Because we’re trying to keep the structure of the top navigation controlled, and because the users are used to fully structured URLs as opposed to having friendly URLs, we would want both those options switched off across all our sub sites.

EDIT (2/02/2017): Added ability to specify the name of the navigation term set to connect to for Managed Navigation.

The PowerShell script below achieves that: Continue reading