Get all Site Collections, Sites & Sub sites form Web Application in SharePoint 2010 using Powershell

Sometimes small requirements take more time,

My colleague wanted to get all the sites , a web application has and he wanted to store it in an excel file.
After spending the whole day, Lately he came to me and asked me to help him with a script and lately publish it.
So here is the code.

  • You have to change the web application and the location of your excel file you want to generate.
  • Save it as a .ps1 file and store it to your location

This code will provide you the following fields in an excel file,

  1. Site’s Title
  2. Url
  3. Site’s ID
  4. Parent Web ID

Code

Get-SPWebApplication My web app here | Get-SPSite -Limit All | Get-SPWeb -Limit All | Select Title, URL, ID, ParentWebID | Export-CSV FileLocationHere\File.csv –NoTypeInformation

  • Click on Start
  • Under Microsoft SharePoint 2010 Products you have SharePoint 2010 Management Shell.
  • Right click on it and run as administrator.
  • Run the following ps1 file and you will get the output generated in an excel file.
  • You have the output

Keep Learning,

Cheers.