This blog will help you to retrieve all the subsites under Site Collections in SharePoint Online, using PowerShell. Method.
Steps
- Open SharePoint Management Shell.
- Copy the code given below and paste it.
- Run the code.
- ##########################
-
- #Script : Below Script will Get All SubSites under the Site Collections in Office 365 SharePoint Online
- #Author : Gowtham Rajamanickam
- #Date :16-03-2017
- #Version:1.0
-
- #########################
-
- #Before Run the Scritp you must load the Client Assembly files
-
- Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
- Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
-
-
-
-
- $UserName= "[email protected]"
- $Password = "Enter your Password here"
-
- $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
-
- #Get the Root Web
- Function Get-Subsites() {
-
-
- $webURL="https://gowthamr.sharepoint.com/"
- $Context = New-Object Microsoft.SharePoint.Client.ClientContext($webURL)
- $Context.Credentials = $credentials
- $Web = $context.Web
- $Context.Load($web)
- $Context.Load($web.Webs)
- $Context.executeQuery()
- Write-host $Web.URL
- foreach ($Subweb in $web.Webs)
- {
- Write-host $Subweb.url
- }
- }
-
- #Call the function
- 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.