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.
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 “Change New Button Order and Default Content Type” link under Content Types section.
  3. On the Change New Button Order page, You can reorder available content types, 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!

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!

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

  • 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 *