Script to get ALL webs in SharePoint Online site collection. Not just the root and one sub level below, but ALL.


In order to use this script you need SharePoint Server 2013 Client Components SDK (x64) installed ! It can be downloaded from here: http://www.microsoft.com/en-us/download/details.aspx?id=35585
  
The output objects from this script are Microsoft.SharePoint.Client.Web (Webs).
This is why in order to receive meaningful information in Powershell you will need proper formatting file loaded or pipe the script to Format-Table -Property Title,Url,Id -AutoSize !
  
With this script is distributed file SharePoint.Client.Format.ps1xml that has display formats for the most SharePoint Online object types.
  
For more information on displaying CSOM in PowerShell see http://spyankulov.blogspot.com/2014/08/display-csom-objects-in-powershell.html
For more information on loading powershell format file(ps1xml)in the current session see https://technet.microsoft.com/en-us/library/hh849884.aspx
  
Author: Ivan Yankulov
Contact: http://spyankulov.blogspot.com
About this script: http://spyankulov.blogspot.com/2015/04/script-to-get-all-webs-in-sharepoint.html

.EXAMPLE
   .\Get-SPOAllWebs.ps1 -SiteUrl https://contoso-online.sharepoint.com -UserName admin@contoso-online.onmicrosoft.com -PassWord demo!234
  
 Description
 -----------
 This will get all webs under SharePoint Online site collection https://contoso-online.sharepoint.com

 

For more information see: Get-Help .\Get-SPOAllWebs -Full


Test, use Q&A, Rate!

Sample:

 

 

PowerShell
Edit|Remove
#########################################################################       
#                         Sample    
#              Full Code is in the File       
#########################################################################  
 
BEGINfunction Get-SPOSubWebs{ 
        Param( 
        [Microsoft.SharePoint.Client.ClientContext]$Context, 
        [Microsoft.SharePoint.Client.Web]$RootWeb 
        ) 
 
 
        $Webs = $RootWeb.Webs 
        $Context.Load($Webs) 
        $Context.ExecuteQuery() 
 
        ForEach ($sWeb in $Webs) 
        { 
            Write-Output $sWeb 
            Get-SPOSubWebs -RootWeb $sWeb -Context $Context 
        } 
    } 
    Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" | Out-Null 
    Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" | Out-Null 
} 
PROCESS{ 
 
    $securePassword = ConvertTo-SecureString $PassWord -AsPlainText -Force 
    $spoCred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName$securePassword) 
    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) 
    $ctx.Credentials = $spoCred 
 
    $Web = $ctx.Web 
    $ctx.Load($Web) 
    $ctx.ExecuteQuery() 
 
    Write-Output $Web 
 
    Get-SPOSubWebs -RootWeb $Web -Context $ctx 
}