Skip to content

Commit 79ad001

Browse files
authored
Merge pull request #839 from kasperbolarsen/main
Added sample showing how to push updates from the CT Hub to the sites…
2 parents 6d33916 + 26af2af commit 79ad001

File tree

4 files changed

+128
-0
lines changed

4 files changed

+128
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
plugin: add-to-gallery
3+
---
4+
5+
# Update Content type from Hub on sites
6+
7+
## Summary
8+
9+
Back in the days Microsoft would update the content types in the content type hub and then push it to all site collections. This is no longer the case. You need to run a script to update the content types in all site collections.
10+
This is such a script. It will check all site collections and update the content type if it exists.
11+
12+
13+
![Example Screenshot](assets/example.png)
14+
15+
16+
# [PnP PowerShell](#tab/pnpps)
17+
18+
```powershell
19+
20+
#when a content type in the Content type gallery is updated and republished
21+
# it is not automaticly updated on the site collections where it is used.
22+
23+
# This script will check every site collection and update the content type
24+
25+
$adminUrl = "https://contoso-admin.sharepoint.com/"
26+
$pnpClientId = "the client id of the PnP Rocks app"
27+
$contenttypeName = "Contoso Project Document"
28+
29+
if(-not $conn)
30+
{
31+
$conn = Connect-PnPOnline -Url $adminUrl -Interactive -ClientId $pnpClientId -ReturnConnection -WarningAction Ignore
32+
}
33+
34+
$allsites = Get-PnPTenantSite -Connection $conn -ErrorAction Stop
35+
foreach($site in $allsites)
36+
{
37+
Write-Host "Site: $($site.Url)"
38+
try
39+
{
40+
$siteUrl = $site.Url
41+
Connect-PnPOnline -Url $siteUrl -Interactive -ClientId $pnpClientId -WarningAction Ignore
42+
$contenttype = Get-PnPContentType -ErrorAction SilentlyContinue -Identity $contenttypeName
43+
if($contenttype)
44+
{
45+
Write-Host "Updating content type: $($ct.Name) at site: $siteUrl " -ForegroundColor Green
46+
Add-PnPContentTypesFromContentTypeHub -ContentTypes $ct.Id -ErrorAction Stop
47+
}
48+
else
49+
{
50+
Write-Host "No content type: $($ct.Name) at site: $siteUrl "
51+
}
52+
}
53+
catch
54+
{
55+
<#Do this if a terminating exception happens#>
56+
throw $_
57+
}
58+
}
59+
60+
61+
```
62+
[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]
63+
***
64+
65+
66+
## Contributors
67+
68+
| Author(s) |
69+
|-----------|
70+
| Kasper Larsen |
71+
72+
[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)]
73+
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-update-contentype-from-hub" aria-hidden="true" />
Loading
Loading
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
[
2+
{
3+
"name": "spo-update-contentype-from-hub",
4+
"source": "pnp",
5+
"title": "Update Content type from Hub on sites",
6+
"shortDescription": "This script will update a specific Content type from the Hub on the sites where it is used",
7+
"url": "https://pnp.github.io/script-samples/spo-update-contentype-from-hub/README.html",
8+
"longDescription": [
9+
""
10+
],
11+
"creationDateTime": "2025-05-22",
12+
"updateDateTime": "2025-05-22",
13+
"products": [
14+
"SharePoint"
15+
],
16+
"metadata": [
17+
{
18+
"key": "PNP-POWERSHELL",
19+
"value": "2.12.0"
20+
}
21+
],
22+
"categories": [
23+
"Deploy",
24+
"Provision",
25+
"Configure",
26+
"Report"
27+
],
28+
"tags": [
29+
"Get-PnPContentType","Add-PnPContentTypesFromContentTypeHub"
30+
],
31+
"thumbnails": [
32+
{
33+
"type": "image",
34+
"order": 100,
35+
"url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/spo-update-contentype-from-hub/assets/preview.png",
36+
"alt": "Preview of the sample Update Content type from Hub on sites"
37+
}
38+
],
39+
"authors": [
40+
{
41+
"gitHubAccount": "kasperbolarsen",
42+
"company": "",
43+
"pictureUrl": "https://github.com/kasperbolarsen.png",
44+
"name": "Kasper Larsen"
45+
}
46+
],
47+
"references": [
48+
{
49+
"name": "Want to learn more about PnP PowerShell and the cmdlets",
50+
"description": "Check out the PnP PowerShell site to get started and for the reference to the cmdlets.",
51+
"url": "https://aka.ms/pnp/powershell"
52+
}
53+
]
54+
}
55+
]

0 commit comments

Comments
 (0)