Get all the views 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:

 
## Get all the views for the specified SharePoint 2010 list using web service in powershell
## Web Service Reference - http://Site/_vti_bin/Views.asmx
$uri="http://serverName:10736/sites/ECT/_vti_bin/Views.asmx?wsdl"
## $listName is the string that contains the list name from which we need to get all the views
[
String]$listName="List"

$viewsWebServiceReference = New-WebServiceProxy -Uri $uri -UseDefaultCredential
## GetViewCollection method is used to return the collection of views for the specified SharePoint 2010 list
[
System.Xml.XmlNode]$xmlNode=$viewsWebServiceReference.GetViewCollection($listName)
## Creates an ViewCollection.xml file in the D:\ which contains all the views for the specified SharePoint 2010 list
$output = New-Object -TypeName System.IO.StreamWriter -ArgumentList "D:\ViewCollection.xml", $false
$output.WriteLine("<?xml version=""1.0"" encoding=""utf-8"" ?>")
$output.WriteLine($xmlNode.OuterXml)
$output.WriteLine()
$output.Dispose()
Write-Host -ForegroundColor Magenta "Displaying all the view Names............"
foreach($view in $xmlNode.View)
{
Write-Host -ForegroundColor Green $view.DisplayName
}


Output:

ViewColl.jpg


ViewCollection.xml:


<?xml version="1.0" encoding="utf-8" ?> 
- <Views xmlns="http://schemas.microsoft.com/sharepoint/soap/">
  <View Name="{D959C5C0-93AF-443B-8446-5011883094E3}" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" Type="HTML" DisplayName="All Items" Url="/sites/ECT/Lists/List/AllItems.aspx" Level="1" BaseViewID="1" ContentTypeID="0x" ImageUrl="/_layouts/images/generic.png" />
</Views>




Ebook Download
View all
Learn
View all