Home > PowerShell, SharePoint 2010, SharePoint Administration > Finding All Content Types in SharePoint 2007/2010 Site Using PowerShell

Finding All Content Types in SharePoint 2007/2010 Site Using PowerShell

If you ever needed to just see which content types are being utilized on your SharePoint 2007/2010 Site you can grab these content types using Power Shell.

Since SharePoint (MOSS) 2007 does not already come pre-installed with Windows PowerShell 2.0 you will have to download a copy and install it onto your WFE  you can grab it here- http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=20430

For SharePoint 2010 PowerShell comes installed so you would just open up the SharePoint 2010 Management Shell.

After installing Windows PowerShell below is the script that can be used to grab all Content Types on a specific Site in SharePoint 2007.

—————————————————————————————————————————————————-

1.  Open up Windows PowerShell 2.0 with Admin rights.
2.  Next Type:

#Load the SharePoint 2007 Assemblies.  This is needed for Windows PowerShell to communicate with SharePoint

[System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral,PublicKeyToken=71e9bce111e942c”) | out-null

$siteUrl=”http://portal/site”
$site=new-object Microsoft.SharePoint.SPSite($siteurl)

$web=$site.RootWeb

foreach($ctype in $web.ContentTypes)
{$ctype.Name}

—————————————————————————————————————————————————–

If you are searching for a specific content type you can use this.

—————————————————————————————————————————————————–

#Load the SharePoint 2007 Assemblies.  This is needed for Windows PowerShell to communicate with

SharePoint[System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral,PublicKeyToken=71e9bce111e942c”) | out-null

$siteUrl=”http://portal/site”
$site=new-object Microsoft.SharePoint.SPSite($siteurl)

$webs = $site.AllWebs

foreach($web in $webs)
{

    foreach($lst in $web.lists)
    {
        
        foreach($item in $lst.Items)
        {
            
            if ($item.ContentType.Name -like “*<name of contenttype>*)
            {Write-Host $web.Url “-” $item.ContentType.Name “-” $item.Url}

        }

    }
    $web.Dispose()
}

—————————————————————————————————————————————————–

For SharePoint 2010 just replace the first three lines of both of these scripts with this line.

$webs = get-spsite http://portal/sites | get-spweb

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

%d bloggers like this: