How to Get All The Sub Web Sites Using SharePoint 2010 Web Service in Powershell


In this article you will see how to get all the titles and URLs of all sites within the current site collection using SharePoint 2010 web service in Powershell.

All sites within the site collection

Share1.jpg

In this you will see how to get all the site's titles and URLs within the current site using SharePoint 2010 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

##===================================================================================
## Automation  : Get all the subsites using SharePoint 2010 Web Service in Powershell 
## Description : Returns the titles and URLs of all sites within the current site collection
## Note:- Need to modify $webURL input parameter  
## Author      : Vijai Anand.R
## Date        : 02-January-2012
##====================================================================================

#----------------------------------------------------- Input Parameters --------------

## $webURL is a string that contains the root site url
$webURL="http://serverName:10736/sites/ECT"

#----------------------------------------------------- GetAllSubWebCollection function -----------------------------------------------------------

function GetAllSubWebCollection()
{
    
$uriWeb=$webURL+"/_vti_bin/Webs.asmx?wsdl"
    
$websWebServiceReference = New-WebServiceProxy -Uri $uriWeb -UseDefaultCredential
     [System.Xml.XmlNode]$webCollXmlNode=$websWebServiceReference.GetAllSubWebCollection()
    
Write-Host -ForegroundColor Magenta "Getting all the sites for: " $webURL
     foreach($web in $webCollXmlNode.Web)
           {             
              
write-host -ForegroundColor Yellow "Title: "$web.Title
               
write-host -ForegroundColor Yellow "URL: "$web.URL  
           }         
}

#----------------------------------------------------- Calling the function -----------------------------------------------------------

GetAllSubWebCollection

Write-Host -ForegroundColor Green "Build Succeeded"

Output

Share2.jpg

Summary

Thus in this article you have seen how to get all the sites within the current site.
 

Up Next
    Ebook Download
    View all
    Learn
    View all