-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #591 from Tanddant/main
🎉 - Added Sample, backup all custom formatting
- Loading branch information
Showing
3 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
--- | ||
plugin: add-to-gallery | ||
--- | ||
|
||
# Extract all custom formatting | ||
|
||
## Summary | ||
|
||
This script stems from a scenario where a client had wiped out some column formatting I had built, and I realized that there was no good way to get it back. | ||
|
||
This script will scrape every list, field, view and ContentType form on the site, and save it in a folder structure that's easy to navigate, and to store in your DevOps repo, or other version control, so you can easily restore it if it gets wiped out, or just see what has changed. | ||
|
||
# [PnP PowerShell](#tab/pnpps) | ||
|
||
```powershell | ||
function get-customFormatting() { | ||
$url = Read-Host -Prompt "Enter the URL of the site you wish to backup custom formatting from" | ||
Connect-PnPOnline $url -Interactive | ||
try { | ||
$web = Get-PnPWeb -Includes Title | ||
} | ||
catch { | ||
Write-Host "Please connect to a site first" -Color Red | ||
return; | ||
} | ||
Write-Host "Backing up formatting for '$($web.Title)', fetching lists"; | ||
$lists = Get-PnPList -Includes Id, Title, Views, Fields, ContentTypes | Where-Object { -not $_.Hidden } | ||
Write-Host "Fetched data - starting backup"; | ||
foreach ($list in $lists) { | ||
$fields = $list.Fields | Where-Object { $_.CustomFormatter -ne $null -and $_.CustomFormatter -ne "" } | ||
foreach ($field in $fields) { | ||
try { | ||
Write-Host "List '$($list.Title)' > field: '$($field.Title)'"; | ||
New-Item -Path "CustomFormatting\$($list.Title)\Columns\" -Name "$($field.Title) ($($field.InternalName)).column-formatter.json" -ItemType File -Value $($field.CustomFormatter | ConvertFrom-Json | ConvertTo-Json -Depth 100) -Force | Out-Null; | ||
} | ||
catch { | ||
Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red; | ||
} | ||
} | ||
$views = $list.Views | Where-Object { $_.CustomFormatter -ne $null -and $_.CustomFormatter -ne "" } | ||
foreach ($view in $views) { | ||
try { | ||
Write-Host "List '$($list.Title)' > `View: '$($view.Title)'"; | ||
New-Item -Path "CustomFormatting\$($list.Title)\Views\" -Name "$($view.Title).view-formatter.json" -ItemType File -Value $($view.CustomFormatter | ConvertFrom-Json | ConvertTo-Json -Depth 100) -Force | Out-Null; | ||
} | ||
catch { | ||
Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red; | ||
} | ||
} | ||
$formCustomizer = $list.ContentTypes | Where-Object { $_.ClientFormCustomFormatter -ne $null -and $_.ClientFormCustomFormatter -ne "" } | ||
foreach ($form in $formCustomizer) { | ||
try { | ||
Write-Host "List '$($list.Title)' > form: '$($form.Name)'"; | ||
New-Item -Path "CustomFormatting\$($list.Title)\Forms\" -Name "$($form.Name).form-formatter.json" -ItemType File -Value $($form.ClientFormCustomFormatter | ConvertFrom-Json | ConvertTo-Json -Depth 100) -Force | Out-Null; | ||
} | ||
catch { | ||
Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red; | ||
} | ||
} | ||
} | ||
} | ||
get-customFormatting; | ||
``` | ||
|
||
[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)] | ||
|
||
*** | ||
|
||
## Contributors | ||
|
||
| Author(s) | | ||
|-----------| | ||
| [Dan Toft](https://twitter.com/tanddant) | | ||
|
||
[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)] | ||
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-export-all-customformatting" 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.
56 changes: 56 additions & 0 deletions
56
scripts/spo-export-all-customformatting/assets/sample.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
[ | ||
{ | ||
"name": "spo-export-all-customformatting", | ||
"source": "pnp", | ||
"title": "Backup all custom formatting on a site", | ||
"shortDescription": "A script that let's you easily backup all custom formatting on a site", | ||
"url": "https://pnp.github.io/script-samples/spo-export-all-customformatting/README.html", | ||
"longDescription": [ | ||
"A script that let's you easily backup all custom formatting on a site, demonstrating the use of the -Includes property to minimize the number of requests to the SharePoint." | ||
], | ||
"creationDateTime": "2023-10-02", | ||
"updateDateTime": "2023-10-02", | ||
"products": [ | ||
"SharePoint" | ||
], | ||
"metadata": [ | ||
{ | ||
"key": "PNP-POWERSHELL", | ||
"value": "2.2.0" | ||
} | ||
], | ||
"categories": [ | ||
|
||
], | ||
"tags": [ | ||
"modern", | ||
"Connect-PnPOnline", | ||
"Get-PnPWeb", | ||
"Get-PnPList", | ||
"-Includes" | ||
], | ||
"thumbnails": [ | ||
{ | ||
"type": "image", | ||
"order": 100, | ||
"url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/spo-export-all-customformatting/assets/preview.png", | ||
"alt": "" | ||
} | ||
], | ||
"authors": [ | ||
{ | ||
"gitHubAccount": "Tanddant", | ||
"company": "Evobis ApS", | ||
"pictureUrl": "https://avatars.githubusercontent.com/u/6947024?s=40&v=4", | ||
"name": "Dan Toft" | ||
} | ||
], | ||
"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" | ||
} | ||
] | ||
} | ||
] |