SharePoint Online: Change Column Order in List using PowerShell

Requirement:  Change Column Ordering in SharePoint Online List.

How to Change Column Order in SharePoint Online? 
To change the order of columns in a SharePoint Online list or library, do the following:
  • Navigate to the list or library where you want to reorder the columns.
  • Click on Settings gear >> list or library settings
  • In the List or Library Settings page, under columns, click the "Column Ordering" link.
  • On the change column ordering page, set the position of columns from drop-down values for the listed columns in the desired order.
    change column order sharepoint online
  • Once all columns are in the desired order, click the OK button to save the order.
Please note, The column order does not affect the order of columns in list or library views! Only New, Edit and View Properties, or the property pane gets these changes. To reorder fields in list view, You have to edit the view and set order or columns.

PnP PowerShell to Change Column Order in SharePoint Online
Here is how to change column order in SharePoint Online using PowerShell.
#Set Variables
$SiteURL = "https://crescent.sharepoint.com/sites/projects"
$ListName = "Projects"

#Set Order of Fields - By its Internal Name
$FieldOrder = @("Title","Description","StartDate", "Project_x0020_Start_x0020_Date","Project_x0020_Status", "Department")
 
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -UseWebLogin
 
#Get the default content type from list
$ContentType = Get-PnPContentType -List $ListName | Select  -First 1
 
#Update column Order in default content type
$FieldLinks =  Get-PnPProperty -ClientObject $ContentType -Property "FieldLinks"
$FieldLinks.Reorder($FieldOrder)
$ContentType.Update($False)
Invoke-PnPQuery 
If you want to set the column order in content types of SharePoint Online list, use: SharePoint Online: Change Column Order in Content Type using PowerShell

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.