How to read Custom template from SharePoint Site
-
09-02-2021 - |
Question
I want read all custom document template and content type template which is used across site collection and sub site level using powershell. can someone suggest?
Causing the multiple entries in CSV:
$List = $web.Lists
$ctx.Load($List)
#$ctx.Load($List.ContentTypes)
$ctx.ExecuteQuery()
$ResultCollection = @()
foreach($CT in $List)
{
$ctx.Load($CT.ContentTypes)
$ctx.ExecuteQuery()
foreach($cc in $CT.ContentTypes)
{
#Write-Host $cc.Name
#Write-Host $cc.DocumentTemplate
# Write-Host $cc.DocumentTemplateUrl
# Write-Host $cc.Description
#Write-Host $cc.Group
# Write-Host $cc.Id
#Write-Host $cc.Parent
$Result = New-Object PSObject
$Result | Add-Member -type NoteProperty -name "SourceURL" -value $Url
$Result | Add-Member -type NoteProperty -name "WebURL" -value $Subweb.Url
$Result | Add-Member -type NoteProperty -name "ContentTypeName" -value $cc.Name
$Result | Add-Member -type NoteProperty -name "CTDocumentTemplate" -value $cc.DocumentTemplate
$Result | Add-Member -type NoteProperty -name "CTDocumentTemplateUrl" -value $cc.DocumentTemplateUrl
$Result | Add-Member -type NoteProperty -name "CTGroup" -value $cc.Group
$Result | Add-Member -type NoteProperty -name "CTDescription" -value $cc.Description
$Result | Add-Member -type NoteProperty -name "ContentTypeID" -value $cc.Id
$Result | Add-Member -type NoteProperty -name "CTParentType" -value $cc.Parent
$ResultCollection+=$Result;
}
#$FileName = $SiteCollectionName + "_DocuTemplateInfo"
$ResultCollection | Export-Csv -path "C:\UserData\z00476kp\Documents\ExportItems\CTTemplateInfo_Modified.csv" -Append -Encoding UTF8 -notypeinformation
}Write-Host "CSV Exported"
Solution
You can refer the below PowerShell script and which can be extended for your needs:
# Paths to SDK. Please verify location on your computer.
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
# Insert the credentials and the name of the admin site
$Username="admin@tenant.onmicrosoft.com"
$AdminPassword=Read-Host -Prompt "Password" -AsSecureString
$AdminUrl="https://tenant.sharepoint.com/sites/teamsitewithlibraries/sub Jump "
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword)
$ctx.Load($ctx.Web.Lists)
$ctx.ExecuteQuery()
foreach( $ll in $ctx.Web.Lists)
{
$ctx.Load($ll.ContentTypes)
try
{
$ctx.ExecuteQuery()
}
catch
{
}
Write-Host $ll.Title -ForegroundColor Green
foreach($cc in $ll.ContentTypes)
{
Write-Output $cc.Name
Now, here using the $cc property you can get the document template name associated with the particular content type......extend your code here.
}
}
Note:
- In the above content type for-each loop collection, using the $cc property you can get the document template name associated with the particular content type......extend your code there.
Reference Article:
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange