-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCTFilterAll.txt
More file actions
34 lines (27 loc) · 1.17 KB
/
CTFilterAll.txt
File metadata and controls
34 lines (27 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Connect to Content Type Hub
Connect-PnPOnline -Url "https://testspdomain.sharepoint.com/sites/ContentTypeHub" -Interactive -ClientId "553a6b41-d10f-418b-be9d-4ba848607c04"
$templateFile = "C:\Scripts\FullTemplate.xml"
$filteredFile = "C:\Scripts\FilteredTemplate.xml"
$targetGroup = "CT Export1"
$targetContentTypes = @("CT Export4")
# Step 1: Export everything for Fields and ContentTypes
Get-PnPSiteTemplate -Out $templateFile -Handlers Fields, ContentTypes -Force
# Step 2: Load XML
[xml]$xml = Get-Content $templateFile
# Step 3: Keep only fields in target group
$fields = $xml.Provisioning.Templates.ProvisioningTemplate.SiteFields.Field
foreach ($field in $fields) {
if ($field.Group -ne $targetGroup) {
$field.ParentNode.RemoveChild($field) | Out-Null
}
}
# Step 4: Keep only specified content types
$contentTypes = $xml.Provisioning.Templates.ProvisioningTemplate.ContentTypes.ContentType
foreach ($ct in $contentTypes) {
if ($ct.Name -notin $targetContentTypes) {
$ct.ParentNode.RemoveChild($ct) | Out-Null
}
}
# Step 5: Save filtered file
$xml.Save($filteredFile)
Write-Host "Filtered template saved to $filteredFile"