Tuesday 20 December 2011

Listing all the Content Types and Fields with PowerShell in Sharepoint 2010

For many reasons at some point you will need to know how many content types you have and all the fields in a particular content type. I wrote a nice script few weeks ago you can run very easily.

Use PowerGui to run it or just copy/paste this code in a file, save it and run it with the native PowerShell.

	write-host ("...Listing Content Types")
	
	$url=  "http://sp_foundation_g/sites/Documents"
	$site = get-spsite $url 
	
	$web = $site.OpenWeb() 
	
	foreach ($contenttype in $web.ContentTypes)
	{	write-host("##################")
		write-host("Content Type Name:" + $contenttype.Name)
		write-host("Fields:")
		foreach ($field in $contenttype.Fields)
		{
			write-host($field.get_InternalName())
		}
	}
	

Enjoy!

No comments: