Content Type Summary Report

145

Content Type Summary Report

Sometimes I get challenged with questions as to which fields are used in which Content Types.  All too often I need to know quickly know the internal name of fields used in Content Types.  I wrote a script that generates a report that you can run to generate a CSV that can easily be Pivoted in Excel for answering such questions. I’m a huge fan of using a Content Type Syndication Hub. With all the Content Types in one location, this report becomes very useful.

$rootwebname="http ://SharePoint"
$rootweb=Get-SPWeb $rootwebname
$MyCTSummaryCSV="L:CTSummary.CSV"
Add-Content  $MyCTSummaryCSV "CT Name,CT Group,Parent CT, CT Read-Only,CT Hidden,Field Internal Name,Field Title,Field Type,ShowInDisplayForm,ShowInEditForm,ShowInNewForm"

$CTs=$rootweb.contenttypes

for ($i=0; $i -lt $CTs.count; $i++)
{
	$CT=$CTs[$i];
	$CTName=$CT.Name;
	$Fields=$CT.Fields;
	for ($j=0; $j -lt $Fields.count; $j++)
	{
		$Field=$Fields[$j];
		
		$OutStr="$($CTName),$($CT.group),$($CT.Parent.Name),$($CT.ReadOnly),$($CT.Hidden),$($Field.staticname),$($Field.Title),$($Field.type),$($Field.ShowInDisplayForm),$($Field.ShowInEditForm),$($Field.ShowInNewForm)"
		Write-Host "." -NoNewline
		Add-Content  $MyCTSummaryCSV $OutStr
		#write-host "$($outstr)"
	}
}

It’s easy to then import this into an Excel file and Pivot away.

Let’s take it one step further and report on which Content Types and fields are in use within each Content Type enabled library in every web of a Site Collection:

$rootwebname="http ://SharePoint dev/div/inv"
$rootweb=Get-SPWeb $rootwebname
$MyCTSummaryCSV="C:UsersplautjDocumentsPowerShellINVCTSummary.CSV"
Add-Content  $MyCTSummaryCSV "web,lib,CT Name,CT Group,Parent CT, CT Read-Only,CT Hidden,Field Internal Name,Field Title,Field Type,ShowInDisplayForm,ShowInEditForm,ShowInNewForm"

$CTs=$rootweb.contenttypes

$site = Get-SPSite $rootwebname
$webs = $site | Get-SPWeb -Limit all
	foreach ($web in $webs)
	{
	$libs = $web.lists;
	foreach ($lib in $libs)
	{
	if ($lib.contenttypesenabled)
	{
	$CTs = $lib.contenttypes;
	for ($i=0; $i -lt $CTs.count; $i++)
	{
		$CT=$CTs[$i];
		$CTName=$CT.Name;
		$Fields=$CT.Fields;
		for ($j=0; $j -lt $Fields.count; $j++)
		{
			$Field=$Fields[$j];
			
			$OutStr="$($web.title),$($lib.title),$($CTName),$($CT.group),$($CT.Parent.Name),$($CT.ReadOnly),$($CT.Hidden),$($Field.staticname),$($Field.Title),$($Field.type),$($Field.ShowInDisplayForm),$($Field.ShowInEditForm),$($Field.ShowInNewForm)"
			Write-Host "." -NoNewline
			Add-Content  $MyCTSummaryCSV $OutStr
			#write-host "$($outstr)"
		}
	}
	}
	}
}

Share this entry

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents

Categories

Categories