Sometimes we need to list all the sites and subsites and sub-subsites of one of the web application. We can do this by either coding or by powershell scripting. Coding is a tedious task so can prefer powershell as long as you have access to the server.
  1. ## SharePoint DLL
  2. [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
  3. $webApplicationURL = Read-Host "Enter Web application"
  4. $webApp = Get-SPWebApplication $webApplicationURL
  5. if($webApp -ne $null)
  6. {
  7. #Write-Host "Web Application : " + $webApp.Name
  8. foreach($siteColl in $webApp.Sites)
  9. {
  10. if($siteColl -ne $null)
  11. {
  12. Write-Host -foregroundcolor red "Site Collection: "$siteColl.Url
  13. Get-SPSite $siteColl | Get-SPWeb -Limit All | Select Title, Url
  14. }
  15. else
  16. {
  17. Echo $siteColl "does not exist"
  18. }
  19. }
  20. }
  21. else
  22. {
  23. Write-Host $webApplicationURL "does not exist, check the WebApplication name"
  24. }