0

We are using SharePoint 2013 and there is multiple content types are created. Some of them are currently in use with multiple list and document libraries but now I want to identify un-used content type and remove them. Can anyone suggest how can I do this or Is there any PowerShell script available to achieve this.

Thanks, Sachin

0
$myContentType = "ContentType Name" 
$myWebApp = "WebApplication URL"  

 if(!(Get-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction:SilentlyContinue))
{ 
Add-PSSnapin Microsoft.SharePoint.PowerShell 
}

$results = @()  

$sites = Get-SPSite –Limit All –WebApplication $myWebApp  
try 
{  
    foreach($site in $sites) 
      {  
        Write-Host "Looking in site– " $site.Url  
        foreach($web in $site.AllWebs)
         {  
            Write-Host $web.Url  
            foreach($list in $web.lists)
            {  
                foreach($ctype in $list.ContentTypes | ? { $_.Name –eq $myContentType})
                {  
                    foreach($item in $list.Items | ? { $_.ContentType.Name –eq $myContentType })
                    {  
                        $RowDetails = @{  
                            "List" = $list.Title  
                            "ListURL" = $list.DefaultView.Url  
                            "ContentType" = $item.ContentType.Name  
                            "Site" = $site.Url  
                            "Web" = $web.Url  
                         }  
                     $results += New-Object PSObject –Property $RowDetails  
                     break  
                    }  
                }  
            }  
            $web.Dispose()  
        }  
        $site.Dispose()  
    }  
} 

catch  
{  
    $e = $_.Exception  
    $line = $_.InvocationInfo.ScriptLineNumber  
    $msg = $e.Message  
    Write-Host –ForegroundColor Red "Caught Exception: $e at $line"  
    Write-Host $msg  
    Write-Host "Something went wrong"
}  

$results | Export-CSV –Path C:\Users\sp_admin_ps\Documents\sachin\ContentTypeUsageReport.csv –NoTypeInformation  
Write-Host " ***** Completed *****"
  • I have prepared PowerShell script for that and it is working fine – Sachin Shinde Oct 4 at 5:27

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.