Saturday, February 27, 2016

SharePoint Online: PowerShell to Get All Subsites in a Site Collection

PowerShell to list all subsites in a SharePoint Online Site collection!

sharepoint online powershell get all subsites
PowerShell sharepoint online get subsites

PowerShell to get all sub-sites in a Site Collection:
Here is the SharePoint online PowerShell to get all subsites
#Load SharePoint Online Assemblies
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"
##Variables for Processing
$SiteUrl = ""
$Password ="Password goes here"
#Setup Credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
#Get the Root Web
Function Get-SPOWeb() {
    $WebURL = $(throw "Please Enter the Site Collection URL")

    #Get Web information and subsites
    $Context = New-Object Microsoft.SharePoint.Client.ClientContext($webURL)
    $Context.Credentials = $credentials
    $Web = $context.Web

    #Do something with the current sub-site
    Write-host $Web.URL

    #Iterate through each subsite in the current web
    foreach ($Subweb in $web.Webs)
        #Call the function recursively to process all subsites underneaththe current web

#Call the function
Get-SPOWeb -WebURL $SiteUrl

This PowerShell gets all subsites from a given site collection. Here is my another article which iterates through all subsites and changes the logo: SharePoint Online: How to Change Site Logo using PowerShell?

Tags: sharepoint online powershell get subsites, sharepoint online powershell list all subsites

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...