spo-findcontenttype

Title: Get the Content type Usage.

Description:

Get the list and document library details about where selected content type is using in site.

Out Put: Out Put will generate in CSV file if match the given content type.

Script:

  1. Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"  
  2. Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"  
  3.    
  4.   
  5. $Usermailid="lakku@myblore.onmicrosoft.com"  
  6. $myPassword=Read-Host -Prompt "Password" -AsSecureString  
  7. $Url="https://myblore.sharepoint.com/sites/fci"  
  8. $context=New-Object Microsoft.SharePoint.Client.ClientContext($Url)  
  9. $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Usermailid, $myPassword)  
  10. $context.Load($context.Web.Lists)  
  11. $context.ExecuteQuery()  
  12.   
  13.   
  14.   
  15. $date = (Get-Date).ToString(“MM/dd/yyyy”)  
  16. $OutPutFilename="ContentTypes-$date.csv";    
  17. "Site URL""," +"ListName""," +"ContentType" | Out-File -Encoding Default -FilePath $OutPutFilename;  
  18.   
  19.   
  20. foreach( $ll in $context.Web.Lists)  
  21.   {  
  22.    
  23.         $context.Load($ll.ContentTypes)  
  24.    
  25.         try  
  26.         {  
  27.             $context.ExecuteQuery()  
  28.         }  
  29.         catch  
  30.         {  
  31.         }  
  32.              
  33.           
  34.       foreach($cc in $ll.ContentTypes)  
  35.          {  
  36.            
  37.         if ($cc.Name -eq "ConteTypeName1" -Or $cc.Name -eq "ConteTypeName2")  
  38.            
  39.            
  40.            {  
  41.                
  42.   
  43.              $ll.Url + "," + $ll.Title + "," + $cc.Name | Out-File -Encoding Default  -Append  -FilePath $OutPutFilename;  
  44.   
  45.   
  46.             }  
  47.          }  
  48.