This blog will help you to retrieve all the subsites under Site Collections in SharePoint Online, using PowerShell. Method.

Steps
  1. Open SharePoint Management Shell.
  2. Copy the code given below and paste it.
  3. Run the code.
  1. ##########################
  2. #Script : Below Script will Get All SubSites under the Site Collections in Office 365 SharePoint Online
  3. #Author : Gowtham Rajamanickam
  4. #Date :16-03-2017
  5. #Version:1.0
  6. #########################
  7. #Before Run the Scritp you must load the Client Assembly files
  8. Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
  9. Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
  10. $UserName= "[email protected]"
  11. $Password = "Enter your Password here"
  12. $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
  13. #Get the Root Web
  14. Function Get-Subsites() {
  15. $webURL="https://gowthamr.sharepoint.com/"
  16. $Context = New-Object Microsoft.SharePoint.Client.ClientContext($webURL)
  17. $Context.Credentials = $credentials
  18. $Web = $context.Web
  19. $Context.Load($web)
  20. $Context.Load($web.Webs)
  21. $Context.executeQuery()
  22. Write-host $Web.URL
  23. foreach ($Subweb in $web.Webs)
  24. {
  25. Write-host $Subweb.url
  26. }
  27. }
  28. #Call the function
  29. Get-SubSites
Was my blog helpful? Was any relevant content missing? If so, please let us know what's confusing or missing at the bottom of this page.

Thanks for reading my blog.