SharePoint Online: Change Content Type Order in New Menu using PowerShell

Requirement: Change content type order in SharePoint Online List using PowerShell.

How to Change Content Type Order in SharePoint Online List or Library?

In a SharePoint Online list with multiple content types, you may want to change the order they appear in the “New” menu or even want to hide them from the new button. The new menu is used to create new items, such as documents or list items, in a library or list, and the order of content types determines which type is selected as the default. By changing the order of content types in the new menu, you can ensure that the most frequently used content type is easily accessible.
sharepoint powershell content type order
You can specify the order and set which of the available ones appear there. To manage content type settings, do the following:

  1. Navigate to the SharePoint Online list or library where content types need to be managed.
  2. Go to List or Library Settings >> On the Settings page, click on the “Change New Button Order and Default Content Type” link under the Content Types section.
  3. On the Change New Button Order page, You can reorder available content types and enable or disable them from appearing in the new menu by setting the visibility check box. The content type which appears at first position becomes the default content type for the list.
    sharepoint online change content type order powershell
  4. Click the OK button to save the changes.

PowerShell to Change Content type Order in SharePoint Online

Here is the PowerShell script to change the order of content types in the SharePoint Online list or library:

#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"
$ContentTypesOrder = @("Contact", "Item", "Announcement")

#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
    $List = $Ctx.Web.Lists.GetByTitle($ListName)
    $Ctx.Load($List)
    $Ctx.Load($List.ContentTypes)
    $Ctx.ExecuteQuery()

    #Create a List for content types order
    $ContentTypeOrder = New-Object System.Collections.Generic.List[Microsoft.SharePoint.Client.ContentTypeId]

    #Arrange Content Types Order
    ForEach($ContentType in $ContentTypesOrder)
    {
        #Get the Content Type from List and Add to Content Type Order List
        $CType = $List.ContentTypes | Where {$_.Name -eq $ContentType}
        If($CType -ne $Null)
        {
            $ContentTypeOrder.Add($CType.Id)
        }
    }
    #Set Content type Order
    $List.RootFolder.UniqueContentTypeOrder = $ContentTypeOrder
    $List.RootFolder.Update()
    $Ctx.ExecuteQuery()
    Write-host -f Green "Content Type Order has been updated Successfully!"#>
}
Catch {
    write-host -f Red "Error: " $_.Exception.Message
}

Please note, this script doesn’t remove or re-add any content types from the list. It simply changes the order of the content type sequence, and the content type in the first index becomes the default content type.

To hide a content type from New menu, just leave its name in $ContentTypesOrder variable!

PnP PowerShell to Set Content Type Order in New Menu

Here is the PnP PowerShell version of the script!

#Set Variables
$SiteURL= "https://crescent.SharePoint.com/sites/Retail"
$ListName = "Contacts"
$ContentTypesOrder = @("Contact", "Item", "Announcement")

#Connect to the site
Connect-PnPOnline –Url $SiteURL -Interactive

#Get the List
$List = Get-PnPList -Identity $ListName -Includes ContentTypes,RootFolder.UniqueContentTypeOrder

#Create a List for content types order
$ContentTypeOrder = New-Object System.Collections.Generic.List[Microsoft.SharePoint.Client.ContentTypeId]

#Arrange Content Types Order
ForEach($ContentType in $ContentTypesOrder)
{
    #Get the Content Type from List and Add to Content Type Order List
    $CType = $List.ContentTypes | Where {$_.Name -eq $ContentType}
    If($CType -ne $Null)
    {
        $ContentTypeOrder.Add($CType.Id)
    }
}

#Set Content type Order
$List.RootFolder.UniqueContentTypeOrder = $ContentTypeOrder
$List.RootFolder.Update()
Invoke-PnPQuery
Write-host -f Green "Content Type Order has been updated Successfully!"

In summary, setting the content type order in the new menu of a library or list in SharePoint Online is a simple process that can help to improve the efficiency of work processes. By making changes to the order, teams can ensure that the most frequently used content types are easily accessible, reducing the time and effort required to create new items.

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

3 thoughts on “SharePoint Online: Change Content Type Order in New Menu using PowerShell

  • This is great but is there an example on how to enable the default documents? When you enable content types, it unchecked default documents in the “New” menu. I want to know how to enable them again, and then reorder them.

    Reply
  • I need your help and support to create multiple three dimensions subfoler in the document library on every month. Currently, we are creating this folder by sync option but it will take more than 2 or 3 days total 50K folder. Could you please guide?

    Reply
    • Also we need to download mentioned url all supporting documents in local folder from share point document library. Here I need to create windows user form to user enter their required location url. So here with help of power shell I pull those documents. Presently I have powershell code for this process for testing. But I don’t know how to create form…

      Reply

Leave a Reply

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