Download all the content type document templates files associated with a library
Summary
The script will download all the document templates assigned to all content types in a library. I created this script as I needed to download the document templates assocaited to a library's content types and could not find as easy way to do it through the UI or did not want to download SharePoint Designer etc.
Implementation
- Open Windows PowerShell ISE or VS Code
- Copy script below to your clipboard
- Paste script into your preferred editor
- Change config variables to reflect the site, library name & download location required
# SharePoint online site URL
$siteUrl = "https://contoso.sharepoint.com/sites/clientfacing"
# Display name of SharePoint document library
$libraryName = "Documents"
# Local path where document templates will be downloaded
$LocalPathForDownload = "c:\temp\"
# Connect to SharePoint online site
Connect-PnPOnline -Url $siteUrl -Interactive
# Get SharePoint list with content types
$list = Get-PnPList -Identity $libraryName -Includes ContentTypes
foreach ($CT in $list.ContentTypes | Where-Object {$_.ReadOnly -eq $false})
{
if ($CT.DocumentTemplateUrl) {
Write-Host "Downloading Document Template: $($CT.DocumentTemplate) for Content Type: $($CT.Name) to $LocalPathForDownload$($CT.DocumentTemplate)"
# Download content type document template
Get-PnPFile -Url $CT.DocumentTemplateUrl -Path $LocalPathForDownload -Filename $($CT.DocumentTemplate) -AsFile
}
}
# Disconnect SharePoint online connection
Disconnect-PnPOnline
Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell
The way you login into PnP PowerShell has changed please read PnP Management Shell EntraID app is deleted : what should I do ?
Contributors
Author(s) |
---|
Leon Armston |
Ganesh Sanap |
Disclaimer
THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.