SharePoint Online: Change the Column Order in Content Type using PowerShell

Requirement: Change Column Order in SharePoint Online Content Type using PowerShell.

How to Change the Column Order in SharePoint Online Content Type?

In SharePoint Online, a content type is a reusable collection of metadata (columns) and settings that define the attributes and behavior of a specific type of content. For example, you could have a content type for invoices, purchase orders, or employee information. Changing the order of columns in a content type can be useful if you want to rearrange the display of information in a list or library. In this article, we will discuss how to change the column order in a content type in SharePoint Online using the SharePoint user interface and PowerShell.

The column order in SharePoint Online content types defines the order of fields displayed in list forms such as New, Edit, and View pages. To change the order in which the columns associated with a content type are displayed on list pages, do the following:

  1. Navigate to the SharePoint Online site where the content type was created.
  2. Click on Settings gear >> Select Site Settings
  3. On the Site Settings page, select the “Site Content Types” link under the “Web Designer Galleries” section.
  4. On the Site Content Types page, click on the name of the content type to be edited >> Click the “Column Order” link from the Columns section.
  5. On the Column Order page, You can change the position from top numbers to set the sort order for the columns.
    sharepoint online change column order in content type powershell
  6. Once done, Set whether the column ordering changes are to be pushed to all content types based on this type.
  7. Click the OK button to save the changes.

This sets the column order for a list content type at the list level. Column order can be set for both list content types and site content types.

SharePoint Online: PowerShell to Set Content Type Column Order

How about re-arranging fields in content type using PowerShell?

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
    
#Set Variables
$SiteURL= "https://crescent.sharepoint.com/sites/Marketing"
$ListName = "Contacts"
$ContentTypeName = "Announcement"
$ColumnOrder = @("Title", "Category", "Body", "Expires")

#Setup Credentials to connect
$Cred = Get-Credential
  
Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

    #Get the List Content Type
    $List = $Ctx.Web.Lists.GetByTitle($ListName)
    $Ctx.Load($List.ContentTypes)
    $Ctx.ExecuteQuery()

    #Get the Content Type from List
    $CType = $List.ContentTypes | Where {$_.Name -eq $ContentTypeName}
    If($CType -ne $Null)
    {
        $Ctx.Load($CType.FieldLinks)
        $Ctx.ExecuteQuery()

        #Set Content type field Order
        $CType.FieldLinks.Reorder($ColumnOrder)
        $CType.Update($False)
        $Ctx.ExecuteQuery()
        Write-host -f Green "Content Type Order has been updated Successfully!"
    }
}
Catch {
    write-host -f Red "Error: " $_.Exception.Message
} 

Change Column Order in Content Type using PnP PowerShell

Let’s change the column order in the site content type using PnP PowerShell.

#Set Variables
$SiteURL = "https://crescent.sharepoint.com/sites/projects"
$ContentTypeName ="Crescent Project Proposal V2"
$FieldOrder = @("Project_x0020_Name","Project_x0020_Description","Project_x0020_Start_x0020_Date","Project_x0020_Status","Project_x0020_Manager")

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive

#Get the content type
$ContentType = Get-PnPContentType -Identity $ContentTypeName

#Update column Order in content type
$FieldLinks =  Get-PnPProperty -ClientObject $ContentType -Property "FieldLinks"
$FieldLinks.Reorder($FieldOrder)
$ContentType.Update($True)
Invoke-PnPQuery

Conclusion

By changing the order of columns in a content type, you can customize the display of information in a list or library in SharePoint Online. This can be particularly useful if you have a large number of columns and want to rearrange the display of information to make it easier to read or if you want to prioritize certain information. By following the steps outlined in this tutorial, you can quickly and easily change the column order in a content type in SharePoint Online. By using PowerShell, you can automate the process of changing the column order in a content type in SharePoint Online. This can save time and effort, especially if you need to make changes to multiple content types or if you need to make changes on a regular basis.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *