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:

  1. ## Get all the views for the specified SharePoint 2010 list using web service in powershell  
  2. ## Web Service Reference - http://Site/_vti_bin/Views.asmx  
  3. $uri="http://serverName:10736/sites/ECT/_vti_bin/Views.asmx?wsdl"   
  4. ## $listName is the string that contains the list name from which we need to get all the views  
  5. [String]$listName="List"   
  6.   
  7. $viewsWebServiceReference = New-WebServiceProxy -Uri $uri -UseDefaultCredential   
  8. ## GetViewCollection method is used to return the collection of views for the specified SharePoint 2010 list  
  9. [System.Xml.XmlNode]$xmlNode=$viewsWebServiceReference.GetViewCollection($listName)  
  10. ## Creates an ViewCollection.xml file in the D:\ which contains all the views for the specified SharePoint 2010 list  
  11. $output = New-Object -TypeName System.IO.StreamWriter -ArgumentList "D:\ViewCollection.xml", $false  
  12. $output.WriteLine("<?xml version=""1.0"" encoding=""utf-8"" ?>")  
  13. $output.WriteLine($xmlNode.OuterXml)  
  14. $output.WriteLine()   
  15. $output.Dispose()   
  16. Write-Host -ForegroundColor Magenta "Displaying all the view Names............"  
  17. foreach($view in $xmlNode.View)  
  18. {  
  19. Write-Host -ForegroundColor Green $view.DisplayName  




Output:

ViewColl.jpg


ViewCollection.xml:

 

  1. <?xml version="1.0" encoding="utf-8" ?>   
  2. <Views xmlns="http://schemas.microsoft.com/sharepoint/soap/">  
  3.      <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" />   
  4. </Views>