Powershell script: to find all content types in use across a sharepoint site collection

 

# Script to find all content types in use across

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Publishing") > $null

$url = "http://YOURSHAREPOINTSITEURL"

$site = new-object Microsoft.SharePoint.SPSite ($url)

$contenttype = $site.rootweb.contenttypes["Document"]

ForEach ($web in $site.AllWebs) {

ForEach ($list in $web.Lists) {

if ($list.BaseTemplate -eq "DocumentLibrary") {

ForEach ($item in $list.Items) {

If ($item.ContentType.Name -ne $contenttype.Name) {

"" + $item.Url + "," + $item.ContentType.Name

}

}

}

}

}

$site.dispose()

To run the script in powershel, run: .\Filename.ps1 >> “C:\results.csv” – this will generate a CSV file with the result.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s