0

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"
1

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:

SharePoint Online content types in Powershell: Get

| improve this answer | |
  • This working!! thanks.. – Liz Jun 25 at 10:05
  • I have one query here this is for content type level. If i want from library document level.. – Liz Jun 25 at 10:10
  • 1
    Glad to hear that it helped you... for library the logic is same... while you are looping through document library collection, inside the foreach loop of the document library, using the document library object, we can get document template for library as well. – Habibur Rahaman Jun 25 at 10:41
  • Thank you so much!! you saved my day.. it is working as expected – Liz Jun 25 at 11:07
  • one more question this document template i am reading site collection level . But i want to read it subsite level recursively.. how can i add – Liz Jun 25 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.