ARTICLE

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

Posted by Vijai Anand Articles | SharePoint 2010 January 03, 2012
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.
Reader Level:

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.
 

Login to add your contents and source code to this article
post comment
     

Very nicely presented article.

Posted by Adora Krause Jan 04, 2012

Thanks everyone:-)

Posted by Vijai Anand Jan 04, 2012

I have to tell you I really like this one

Posted by Akash Ahlawat Jan 04, 2012

Really very nice

Posted by Jimmy Underwood Jan 04, 2012

Nice work.

Posted by Akshay Teotia Jan 04, 2012
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts