Skip to content

Commit

Permalink
Merge pull request #623 from Amanp17/main
Browse files Browse the repository at this point in the history
pnp-reorder-list-content-type
  • Loading branch information
pkbullock authored Nov 15, 2023
2 parents ffe8f75 + 0fdb1d7 commit 44976c1
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
68 changes: 68 additions & 0 deletions scripts/spo-reorder-list-content-type/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
plugin: add-to-gallery
---

# Reorder Content Types in SharePoint List

## Summary

This guide details how to rearrange content types in a SharePoint list using PnP PowerShell.

![Example Screenshot](assets/ContentTypes.png)


# [PnP PowerShell](#tab/pnpps)

```powershell
# Specify the Site URL
$SiteURL = "https://contoso.sharepoint.com/"
# Connect to SharePoint online admin center
Connect-PnPOnline -Url $SiteURL -Interactive
# Note Down the Content Types order you need
$ContentTypesOrder = @("Site Page","Web Part Page","Wiki Page","Repost Page")
# Specify the List Name
$ListName = "Site Pages"
#Get the List Details
$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
# Disconnect SharePoint online connection
Disconnect-PnPOnline
```

[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]

***

## Contributors

| Author |
|-----------|
| [Aman Panjwani](https://www.linkedin.com/in/aman-17-panjwani/) |

[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)]
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-reorder-list-content-type" aria-hidden="true" />
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions scripts/spo-reorder-list-content-type/assets/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[
{
"name": "spo-reorder-list-content-type",
"source": "pnp",
"title": "Reorder Content Types in SharePoint List",
"shortDescription": "This script guides how to rearrange content types in a SharePoint list using PnP PowerShell.",
"url": "https://pnp.github.io/script-samples/spo-reorder-list-content-type/README.html",
"longDescription": [
"This comprehensive guide provides step-by-step instructions on efficiently reordering content types within a SharePoint list, leveraging the capabilities of PnP PowerShell. Streamline your information organization"
],
"creationDateTime": "2023-11-15",
"updateDateTime": "2023-11-15",
"products": [
"SharePoint"
],
"metadata": [
{
"key": "PNP-POWERSHELL",
"value": "2.1.1"
}
],
"categories": [
"Configure"
],
"tags": [
"SharePoint Online",
"ContentTypes",
"Connect-PnPOnline",
"Invoke-PnPQuery",
"Disconnect-PnPOnline"
],
"thumbnails": [
{
"type": "image",
"order": 100,
"url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/spo-reorder-list-content-type/assets/preview.png",
"alt": "Content Types in SharePoint Lists"
}
],
"authors": [
{
"gitHubAccount": "Amanp17",
"pictureUrl": "https://github.com/Amanp17.png",
"name": "Aman Panjwani"
}
],
"references": [
{
"name": "Want to learn more about PnP PowerShell and the cmdlets",
"description": "Check out the PnP PowerShell site to get started and for the reference to the cmdlets.",
"url": "https://aka.ms/pnp/powershell"
}
]
}
]

0 comments on commit 44976c1

Please sign in to comment.