Get all the columns for the specified SharePoint 2010 site 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:

 
## Get all the site columns using SharePoint 2010 web service in powershell
$uri="http://serverName:10736/sites/ECT/_vti_bin/Webs.asmx?wsdl"
## Web Service Reference - http://Site/_vti_bin/Webs.asmx
$websWebServiceReference = New-WebServiceProxy -Uri $uri -UseDefaultCredential

[
System.Xml.XmlNode]$xmlNode=$websWebServiceReference.GetColumns()
## Creates an Columns.xml file in the D:\ which contains column definitions for the columns available on the site
$output = New-Object -TypeName System.IO.StreamWriter -ArgumentList "D:\Columns.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 site Columns................"
foreach($node in $xmlNode.Field)
{
Write-Host -ForegroundColor Green $node.Name
}


Columns.xml:

<?xml version="1.0" encoding="utf-8" ?> 
- <Fields xmlns="http://schemas.microsoft.com/sharepoint/soap/"> 
<Field ID="{4dd7e525-8d6b-4cb4-9d3e-44ee25f973eb}"
Name
="Created_x0020_By"
SourceID
="http://schemas.microsoft.com/sharepoint/v3"
StaticName
="Created_x0020_By"
Group
="_Hidden"
ReadOnly
="TRUE"
Hidden
="TRUE"
Type
="Text"
DisplayName
="Document Created By" /> ......








<Fields/>