SharePoint: PowerShell to find all Content Types that use a Site Column


Just another little PowerShell script for SharePoint…

The following will report all Content Types in a single Site Collection that uses a particular Site Column.

This is related to this article PowerShell to find SharePoint Content Types.


The Script:

$site = Get-SPSite http://sharepoint/sites/training   #your URL here!
$web = $site.RootWeb

# Get the GUID of your Site Column
$guid = $fields["End Time"].id            # your Site Column name here

# Find all content types that use that column type
#  This will display all content types and list details if there match for the column

$ct = $web.AvailableContentTypes 
for ($i=0; $i -lt $ct.Count; $i++) 
  for ($j=0; $j -lt $ct[$i].Fields.Count; $j++) 
    if ($ct[$i].Fields[$j].id -eq $guid)
      Write-Host $ct[$i].Name " has column"


For SharePoint 2007 replace the first line with these two:


$site = New-Object Microsoft.SharePoint.SPSite(http://yourserver/sites/yoursite)



1 comment:

Darren said...

Code typo on the Field Line. Had to change

$guid = $fields["End Time"].id
$guid = $web.fields["End Time"].id

Works as expected once updated.

Note to spammers!

Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.