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

Populating Large Lists using PowerShell

Below is a PowerShell snippet that creates dummy data in a list for large data volume testing.

Add-PSSnapin Microsoft.SharePoint.Powershell

$site = Get-SPSite("http://site-url");
$web = $site.OpenWeb("web-url");
$list = $web.Lists.TryGetList("Large List");

if ($list) {
    $colours = "Red", "Green", "Blue";
    $brands = "Toyota", "Mazda", "Volkswagon", "Hyundai", "BMW", "Mercedes", "Suzuki";

    for($i = 0; $i -le 3000; $i++) {
        $item = $list.AddItem();
        $item["Title"] = (Get-Date).Ticks
        $item["Colour"] = $colours[(Get-Random -Maximum $colours.Count)];
        $item["Year"] = Get-Random -Minimum 2000 -Maximum 2017
        $item["Brand"] = $brands[(Get-Random -Maximum $brands.Count)];


Turn Scripting Capabilities On in SharePoint Online

By default, SharePoint Online tenancies have scripting capabilities turned off, closing off a myriad of useful features such as being able to upload certain file types (.aspx, .master), being able to create custom page layouts, and even using the Content Editor and Script Editor web parts.

For more information, see:

We can enable scripting from the Office 365 SharePoint Admin Centre, as detailed in the link above. However, the changes are not instant and take up to 24 hours before being applied.

Or we can instead enable scripting on a specific site collection for it to take effect immediately, using the SharePoint Online Management Shell:

Connect-SPOService <SP Admin Centre URL>
Set-SPOSite <Site URL> -DenyAddAndCustomizePages 0