Get all the list content types for the specified SharePoint 2010 list using web service in powershell

Steps Involved:

  1. Open SharePoint 2010 Management Shell by going to Start | All Programs | SharePoint | Microsoft SharePoint 2010 Products | SharePoint 2010 Management Shell (Run as Administrator).
  2. Run the following script.

Powershell Script:

 
## Input Parameters required for getting all the content types for the specified SharePoint 2010 list
$uri="http://serverName:10736/sites/ECT/_vti_bin/Lists.asmx?wsdl"
[
string] $contentTypeId="0x01"
[
string] $listName="List"


$listWebServiceReference = New-WebServiceProxy -Uri $uri -UseDefaultCredential
[
System.Xml.XmlNode]$xmlNode=$listWebServiceReference.GetListContentTypes($listName,$contentTypeId)
## Creates an ContentTypes.xml file in the D:\ which contains content type definition schemas for the specified SharePoint 2010 list.
$output = New-Object -TypeName System.IO.StreamWriter -ArgumentList "D:\ContentTypes.xml", $false
$output.WriteLine("<?xml version=""1.0"" encoding=""utf-8"" ?>")
$output.WriteLine($xmlNode.OuterXml)
$output.WriteLine()
$output.Dispose()
write-host -ForegroundColor Magenta "Getting all the content types for the specified list........."
foreach($node in $xmlNode.ContentType)
{
write-host -ForegroundColor Green "Content Type Name: " $node.Name
}




Ebook Download
View all
Learn
View all